Advertisement
TheIncgi

Nonsense Gui

Jan 8th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.42 KB | None | 0 0
  1. import javafx.animation.AnimationTimer;
  2. import javafx.application.Application;
  3. import javafx.event.EventHandler;
  4. import javafx.geometry.Pos;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Alert;
  7. import javafx.scene.control.Alert.AlertType;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.control.ButtonType;
  10. import javafx.scene.control.Label;
  11. import javafx.scene.input.MouseDragEvent;
  12. import javafx.scene.layout.GridPane;
  13. import javafx.scene.layout.Pane;
  14. import javafx.stage.Stage;
  15.  
  16. public class Amazing extends Application{
  17.     public static void main(String[] args) {
  18.         launch();
  19.     }
  20.  
  21.     private Stage stage;
  22.     private Scene scene;
  23.     private Pane  pane;
  24.     @Override
  25.     public void start(Stage primaryStage) throws Exception {
  26.         (stage = primaryStage).setScene(scene = new Scene(pane = new Pane(), 300, 300));
  27.         primaryStage.setResizable(false);
  28.         populate();
  29.        
  30.         primaryStage.show();
  31.     }
  32.  
  33.     private void populate() {
  34.         Label label = new Label("Java?");
  35.         Button yes = new Button("Yes"), no = new Button("No");
  36.         yes.setOnAction((e)->{notify("K thnkx");});
  37.         GridPane gp = new GridPane();
  38.         pane.getChildren().add(gp);
  39.         gp.translateXProperty().bind(pane.widthProperty().divide(2).subtract(gp.widthProperty().divide(2)));
  40.         gp.translateYProperty().bind(pane.heightProperty().divide(2).subtract(gp.heightProperty()).divide(2));
  41.         gp.add(label, 0, 0, 2, 1);
  42.         gp.addRow(1, yes, no);
  43.         gp.setHgap(20);
  44.         gp.setVgap(20);
  45.         AnimationTimer at = new AnimationTimer() {
  46.             long nextRot = 0;
  47.             @Override
  48.             public void handle(long _unusedNanosecondTimer) {
  49.                 if(nextRot <= System.currentTimeMillis()) {
  50.                     pane.setRotate(pane.getRotate()+3);
  51.                     nextRot = System.currentTimeMillis()+10;
  52.                 }
  53.             }
  54.         };
  55.        
  56.         no.setOnMouseEntered((e)->{
  57.             at.start();
  58.         });
  59.         no.setOnMouseExited((e)->{
  60.             at.stop();
  61.         });
  62.        
  63.        
  64.         no.setOnAction((e)->{
  65.             gp.getChildren().removeAll(yes,no);
  66.             gp.addRow(1, no, yes);
  67.             attemptToClickNo = true;
  68.             yes.fire();
  69.         });
  70.         stage.setOnCloseRequest((e)->{
  71.             e.consume();
  72.             notify("The real exit button is \"Yes\"");
  73.         });
  74.         yes.setOnAction((e)->{
  75.             notify("Thank you for choosing yes." + (attemptToClickNo? "\n (Buttons swapped)":""));
  76.             stage.close();
  77.         });
  78.     }
  79.     private static volatile boolean attemptToClickNo = false;
  80.     private void notify(String msg) {
  81.         Alert alert = new Alert(AlertType.INFORMATION, msg, ButtonType.OK);
  82.         alert.showAndWait();
  83.     }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement