新的線程類型。不能在循環中使用線程中的按鈕
我現在的代碼;
public boolean running = false;
private void jStartButton1ActionPerformed(java.awt.event.ActionEvent evt){
running = true;
(new Thread(new Home())).start();
}
private void jStopButton2ActionPerformed(java.awt.event.ActionEvent evt) {
running = false;
System.out.println("trying to stop");
}
public void run() {
while(running){
//continously run code from a file thats updated every few seconds, running=false when its found what its looking for
}
}
jStopButton2正在處理中的運行設置爲false中調試,但它從來不承認由run()線程。 run()有它自己的running = false當它發現它尋找的東西時(它會停止while循環),它會建立它,但現在如果我想停止,我無法手動停止它。
我知道我有我的線程錯了,有什麼幫助嗎?難道是線程內的所有東西都被鎖定了嗎?所以它不能識別正在更改的運行布爾值?我將如何去改變它? o.o
任何幫助將不勝感激。
完美,謝謝:) – Pengiuns