我有兩個按鈕JFramePanel運行此代碼:殺的Java proccess同時運行一個while循環
public void runProc(){
while(true){
System.out.println("Running...");
PrintWriter outputStream = null;
try {
outputStream = new PrintWriter (FILENAME);
}
catch (FileNotFoundException e) {
try {
Process failedToWriteFile = Runtime.getRuntime().exec(DIALOGBOX);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
outputStream.println("hello");
outputStream.close();
System.out.println("");
try {
TimeUnit.SECONDS.sleep(2);
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Path d= Paths.get(FILENAME);
try {
Files.delete(d);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
TimeUnit.SECONDS.sleep(3);
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void killProc(){
System.exit(0);
}
當我按下啓動代碼運行,但是當我按下停止它不會停止 開始按鈕保持單擊並且停止按鈕不起作用 我在做什麼錯了?
我們應該如何永遠不知道爲什麼你的按鈕正在做些什麼?你不覺得我們需要查看按鈕/面板背後的代碼來回答你的問題嗎?你認爲我們在這裏嚮導? – GhostCat