【发布时间】:2014-10-19 19:16:41
【问题描述】:
public void myMethod()
{
if (capture.isOpened()) {
while (true) { //This is The main issue.
capture.read(webcam_image);
if (!webcam_image.empty()) {
webcam_image = my_panel.detect(webcam_image);
temp = my_panel.matToBufferedImage(webcam_image);
my_panel.setimage(temp);
my_panel.repaint();
System.out.print("."); // It should prints "." but the above code doesn't works.
} else {
System.out.println(" --(!) No captured frame -- Break!");
break;
}
}
}
}
这是调用上述方法的代码... 实际上它是一个可以在单击菜单时触发的 ActionEvent。
if (e.getActionCommand().equals("goLive")) {
System.out.println("Live...");
myMethod();
}
实际上我知道这是无限 while 循环的问题,但在这里我需要不惜一切代价设置这个条件。
【问题讨论】:
-
或
SwingWorker,详情请见Worker Threads and SwingWorker
标签: java multithreading swing while-loop infinite-loop