0
這個程序要在單獨的線程中執行嗎?java事件隊列
class Counter extends Thread {
public void run() {
EventQueue.invokeLater(new Runnable() {
public void run() {
for(int i=0;isCounting;i++) {
try {Thread.currentThread().sleep(100);}
catch (InterruptedException e) {e.printStackTrace();}
setTitle(""+i);
}
}
});
}
}
它是擴展JFrame的類的一部分。現在,如果我在JFrame擴展類的構造函數中的某個地方啓動此類的實例,它是否會在單獨的線程或EDT中運行?因爲我試過了,顯然它運行在EDT,因爲程序卡住了...
參考http://stackoverflow.com/questions/3541373/should-we-use-eventqueue-invokelater-for-any-gui-update- in-java-desktop-applicati和這個http://www.javapractices.com/topic/TopicAction.do?Id=153 – Favonius 2011-04-25 15:50:50