다른 스레드를 닫지 않고 창을 닫을 때 JavaFX 응용 프로그램을 실행하는 스레드를 종료하려고합니다. 나는이 프로그램을 시작할 때 테스트 목적으로JavaFX : 창 닫기 후 응용 프로그램 스레드가 종료되지 않습니다.
package testIt;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import java.io.IOException;
public class MemoryVisualizerApp extends Application{
public static void main(String[] args) {
launch(args);
}
//Setup the scene and launch with given properties
@Override
public void start(Stage primaryStage) throws IOException{
Parent root = FXMLLoader.load(getClass().getResource("/MemoryVisualizer.fxml"));
Scene scene = new Scene(root, 650, 340);
//Set whether the screen should be re-sizable (possibly best size = default)
primaryStage.setResizable(true);
primaryStage.setMinHeight(300);
primaryStage.setMinWidth(550);
primaryStage.setTitle("MINT Performance");
primaryStage.setScene(scene);
scene.getStylesheets().add("testIt/MemoryVisualizer.css");
primaryStage.show();
primaryStage.show();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>()
{
public void handle(WindowEvent e){
System.out.println("test");
try {
stop();
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
}
}
는이 앱이 유일하게 실행, 그리고 내가 창을 닫으 때, 전체 프로그램을 종료해야합니다이 내 응용 프로그램 클래스입니다. 하지만 난 여전히 프로그램을 종료 할 수있는 옵션이 있습니다 (나는 이클립스를 사용하고 있으며 빨간색 사각형은 여전히 클릭 가능합니다), 스레드가 여전히 활성화되어 있음을 의미합니다.
GUI 창을 닫은 후에이 스레드가 종료되도록하려면 어떻게해야합니까?
'setOnCloseRequest()'를 사용하지 않고 종료해야합니다. 이 메서드를 제거하고 사용한 두 stage.show() 중 하나를 주석 처리 한 후에 어떤 일이 발생하는지 알려 주실 수 있습니까? – ItachiUchiha