I want a modal window and so I added these lines of code in program:
primaryStage.initOwner(primaryStage);
primaryStage.initModality(Modality.WINDOW_MODAL);
But If I start my program with these lines of code I get an exception:
Exception in Application start method Exception in thread "main"
java.lang.NoSuchMethodException: P8.Hauptfenster.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1786)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:126)
What is the reason of this exeption?
Main Window:
public class Hauptfenster extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane bp = new BorderPane();
FlowPane fp = new FlowPane();
Button bild = new Button("Bilderfassung");
Button audio = new Button("Audioerfassung");
Bildererfassung bildererfassung = new Bildererfassung();
bild.setOnAction(event -> bildererfassung.showBilderfassungDialog());
HBox hb = new HBox();
hb.setAlignment(Pos.CENTER);
hb.getChildren().addAll(bild, audio);
hb.setSpacing(10.0);
bp.setCenter(hb);
Scene scene = new Scene(bp, 400, 400);
primaryStage.initOwner(primaryStage);
primaryStage.initModality(Modality.WINDOW_MODAL);
primaryStage.setTitle("Medienverwaltung");
//primaryStage.initOwner(primaryStage);
//primaryStage.initModality(Modality.WINDOW_MODAL);
primaryStage.setScene(scene);
primaryStage.show();
}
}
2. Window:
public class Bildererfassung {
public void showBilderfassungDialog() {
Stage stage = new Stage();
GridPane gp = new GridPane();
gp.setAlignment(Pos.CENTER);
gp.setPadding(new Insets(5));
gp.setHgap(5);
gp.setVgap(5);
Label lblTitel = new Label("Titel:");
gp.setHalignment(lblTitel, HPos.RIGHT);
Label lblOrt = new Label("Ort:");
gp.setHalignment(lblOrt, HPos.RIGHT);
Label lblAufnahmejahr = new Label("Aufnahmejahr:");
gp.setHalignment(lblAufnahmejahr, HPos.RIGHT);
TextField tfTitel = new TextField();
TextField tfOrt = new TextField();
TextField tfAufnahmejahr = new TextField();
Button btnNeu = new Button("Neu");
Button btnAbbrechen = new Button("Abbrechen");
HBox hb = new HBox();
hb.getChildren().addAll(btnNeu, btnAbbrechen);
hb.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
hb.setAlignment(Pos.CENTER);
hb.setSpacing(5.0);
gp.add(lblTitel, 0, 0);
gp.add(lblOrt, 0, 1);
gp.add(lblAufnahmejahr, 0, 2);
gp.add(tfTitel, 1, 0);
gp.add(tfOrt, 1, 1);
gp.add(tfAufnahmejahr, 1, 2);
gp.add(hb, 1, 3);
BorderPane bp = new BorderPane();
bp.setCenter(gp);
Scene scene = new Scene(bp);
stage.setScene(scene);
stage.setTitle("Bilderfassung");
stage.show();
}
}