Advertisement
apl-mhd

JavaSceneToggle

Nov 26th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.EventHandler;
  5. import javafx.event.Event;
  6. import javafx.fxml.FXMLLoader;
  7. import javafx.scene.Parent;
  8. import javafx.scene.Scene;
  9. import javafx.scene.layout.VBox;
  10. import javafx.stage.Stage;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.control.Label;
  13.  
  14. //import java.awt.*;
  15.  
  16.  
  17. //package sample;
  18.  
  19. import javafx.application.Application;
  20. import javafx.event.Event;
  21. import javafx.event.EventHandler;
  22. import javafx.fxml.FXMLLoader;
  23. import javafx.scene.Parent;
  24. import javafx.scene.Scene;
  25. import javafx.scene.control.Button;
  26. import javafx.scene.layout.StackPane;
  27. import javafx.stage.Stage;
  28.  
  29. import java.awt.event.ActionEvent;
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. public class Main extends Application {
  37.  
  38.     Stage window;
  39.     Scene scene1, scene2;
  40.  
  41.  
  42.  
  43.     @Override
  44.     public void start(Stage primaryStage) throws Exception{
  45.  
  46.         window = primaryStage;
  47.  
  48.         Label label1 = new Label("welcome to first stage");
  49.         Button button1 = new Button("got to scene two");
  50.  
  51.         button1.setOnAction(e->window.setScene(scene2));
  52.  
  53.         VBox layout1 = new VBox(20);
  54.  
  55.         layout1.getChildren().addAll(label1,button1);
  56.  
  57.         scene1 = new Scene(layout1,200,200);
  58.  
  59.  
  60.         Button button2 = new Button("goto one");
  61.  
  62.         StackPane layout2 = new StackPane();
  63.  
  64.         button1.setOnAction(e->window.setScene(scene2));
  65.         button2.setOnAction(e->window.setScene(scene1));
  66.  
  67.         layout2.getChildren().add(button2);
  68.         scene2 = new Scene(layout2,600,300);
  69.  
  70.         window.setScene(scene1);
  71.         window.setTitle("Sabi");
  72.         window.show();
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.     }
  80.  
  81.  
  82.     public static void main(String[] args) {
  83.         launch(args);
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement