Advertisement
iuliaa

Untitled

Apr 23rd, 2020
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.ActionEvent;
  5. import javafx.event.EventHandler;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.Label;
  8. import javafx.scene.layout.StackPane;
  9. import javafx.fxml.FXMLLoader;
  10. import javafx.scene.Parent;
  11. import javafx.scene.Scene;
  12. import javafx.scene.layout.VBox;
  13. import javafx.stage.Stage;
  14.  
  15. public class Main extends Application{
  16.     Stage window;
  17.     Scene scene1, scene2;
  18.     public static void main(String[] args) {
  19.         launch(args);
  20.     }
  21.  
  22.     @Override
  23.     public void start(Stage primaryStage) throws Exception {
  24.         window=primaryStage;
  25.         Label label1 = new Label("This is the first scene");
  26.         Button button1 = new Button("Go to scene 2");
  27.         button1.setOnAction(e->window.setScene(scene2));
  28.         //layout 1 vertical column
  29.         VBox layout1 = new VBox(20);
  30.         layout1.getChildren().addAll(label1,button1);
  31.         scene1 = new Scene(layout1, 300, 250);
  32.         //button 2
  33.         Button button2 = new Button("Go back to scene 1");
  34.         button2.setOnAction(e->window.setScene(scene1));
  35.  
  36.         //Layout 2
  37.         StackPane layout2 = new StackPane();
  38.         layout2.getChildren().add(button2);
  39.         scene2=new Scene(layout2,600,300);
  40.  
  41.         window.setScene(scene1);
  42.         window.setTitle("Titlu");
  43.         window.show();
  44.     }
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement