0

I have two Java classes. Let's take it as A & B

I have a Label B1 in class A and when I click 'B1', I want the next java FX class to be opened.

I tried using this code, but it throws a series of exceptions and I couldn't achieve the task.

CLASS A :

label.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
           Application.launch( B.class );
        }
    });

CLASS B :

 public class B extends Application{
 public void start(Stage primaryStage) throws Exception {
    VBox vb = new VBox();
    Label sub = new Label("TEST");
    primaryStage.initStyle(StageStyle.UNDECORATED);
    Scene scene = new Scene(vb, 630, 500);
    primaryStage.setScene(scene);
    vb.getChildren().addAll(sub);
    primaryStage.show();
 }
}

P.S.

I am not using FXML to add style to the scenes.

It Assistors
  • 998
  • 2
  • 14
  • 29
  • 1
    Why do you have more than one `Application` class in a single application? The `Application` represents the application. The [documentation](http://docs.oracle.com/javase/8/javafx/api/javafx/application/Application.html#launch-java.lang.String...-) explicitly states that you can't call `launch()` more than once. – James_D Feb 08 '17 at 18:47
  • I have two classes inside the same java package which are nothing but two FX apps. I want to load class B from A @James_D – It Assistors Feb 08 '17 at 18:50
  • you can not do that, this `Application.launch( B.class );` can only be called once do you have access or can you control the other javafx application? – Elltz Feb 08 '17 at 18:50
  • Is it possible if i create a new inner class with another stage and then I load it ?? – It Assistors Feb 08 '17 at 19:16

0 Answers0