Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.animation.AnimationTimer;
- import javafx.application.Application;
- import javafx.event.EventHandler;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Alert.AlertType;
- import javafx.scene.control.Button;
- import javafx.scene.control.ButtonType;
- import javafx.scene.control.Label;
- import javafx.scene.input.MouseDragEvent;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.Pane;
- import javafx.stage.Stage;
- public class Amazing extends Application{
- public static void main(String[] args) {
- launch();
- }
- private Stage stage;
- private Scene scene;
- private Pane pane;
- @Override
- public void start(Stage primaryStage) throws Exception {
- (stage = primaryStage).setScene(scene = new Scene(pane = new Pane(), 300, 300));
- primaryStage.setResizable(false);
- populate();
- primaryStage.show();
- }
- private void populate() {
- Label label = new Label("Java?");
- Button yes = new Button("Yes"), no = new Button("No");
- yes.setOnAction((e)->{notify("K thnkx");});
- GridPane gp = new GridPane();
- pane.getChildren().add(gp);
- gp.translateXProperty().bind(pane.widthProperty().divide(2).subtract(gp.widthProperty().divide(2)));
- gp.translateYProperty().bind(pane.heightProperty().divide(2).subtract(gp.heightProperty()).divide(2));
- gp.add(label, 0, 0, 2, 1);
- gp.addRow(1, yes, no);
- gp.setHgap(20);
- gp.setVgap(20);
- AnimationTimer at = new AnimationTimer() {
- long nextRot = 0;
- @Override
- public void handle(long _unusedNanosecondTimer) {
- if(nextRot <= System.currentTimeMillis()) {
- pane.setRotate(pane.getRotate()+3);
- nextRot = System.currentTimeMillis()+10;
- }
- }
- };
- no.setOnMouseEntered((e)->{
- at.start();
- });
- no.setOnMouseExited((e)->{
- at.stop();
- });
- no.setOnAction((e)->{
- gp.getChildren().removeAll(yes,no);
- gp.addRow(1, no, yes);
- attemptToClickNo = true;
- yes.fire();
- });
- stage.setOnCloseRequest((e)->{
- e.consume();
- notify("The real exit button is \"Yes\"");
- });
- yes.setOnAction((e)->{
- notify("Thank you for choosing yes." + (attemptToClickNo? "\n (Buttons swapped)":""));
- stage.close();
- });
- }
- private static volatile boolean attemptToClickNo = false;
- private void notify(String msg) {
- Alert alert = new Alert(AlertType.INFORMATION, msg, ButtonType.OK);
- alert.showAndWait();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement