0
でjavafxのステージを閉じることができません。私はJavaFxの初心者です。ステージを閉じるだけで問題が発生しています。基本的には、確認ボックスコントローラであるクラスを作成しようとしています。 「はい」ボタンとし、「NO」ボタンが、ステージがアプリケーションを終了し、継続すべきいずれかの方法があります:アクションイベント関数
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
// more imports...
public class ConfirmBoxController implements IView {
public javafx.scene.control.Button BTN_save;
public javafx.scene.control.Label label_Message;
private Stage stage;
private boolean answer;
private String title;
private String message;
public ConfirmBoxController(){
this("Confirmation","Are you sure?");
}
public ConfirmBoxController(String title, String message){
this.title = title;
this.message = message;
stage = new Stage();
}
public boolean confirm(){
try{
stage = new Stage();
FXMLLoader fxmlLoader = new FXMLLoader();
Parent root = fxmlLoader.load(getClass().getResource("ConfirmBox.fxml").openStream());
Scene scene = new Scene(root, 250, 140);
stage.setTitle(title);
stage.setScene(scene);
stage.showAndWait();
return answer;
}
catch(Exception E){
E.printStackTrace();
return true;
}
}
public void yes(ActionEvent actionEvent) {
answer = true;
stage.close();
}
public void no(ActionEvent actionEvent) {
answer = false;
stage.close();
}
注:iViewが空のインターフェースです。 基本的にステージが現れ、ボタンをクリックすることができ、ボタンをクリックすると「はい」と「いいえ」という機能が登録されているので、これが登録されていることがわかります。しかし、何も起こりません。
私は何か基本的なことを監督していると確信していますが、これを正しく行う方法が見つかりませんでした。ありがとうございました。
は素晴らしい仕事こと、ありがとうございます。私は本当に理由を理解していない。 また、関数 "yes"と "no"が "answer"の値を変更しない理由も知っていますか?つまり、confirmは常にデフォルト値の "answer"を返します。 –