zoukankan      html  css  js  c++  java
  • JavaFx EventHandler

    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Menu;
    import javafx.scene.control.MenuBar;
    import javafx.scene.control.MenuItem;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    
    public class Main extends Application {
    
        public static void main(String[] args) {
            Application.launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("Title");
            Group root = new Group();
            Scene scene = new Scene(root, 400, 250, Color.WHITE);
    
            MenuBar menuBar = new MenuBar();
            EventHandler<ActionEvent> action = changeTabPlacement();
    
            Menu menu = new Menu("Direction");
            MenuItem left = new MenuItem("Left");
    
            left.setOnAction(action);
            menu.getItems().add(left);
    
            MenuItem right = new MenuItem("Right");
            right.setOnAction(action);
            menu.getItems().add(right);
    
            MenuItem top = new MenuItem("Top");
            top.setOnAction(action);
            menu.getItems().add(top);
    
            MenuItem bottom = new MenuItem("Bottom");
            bottom.setOnAction(action);
            menu.getItems().add(bottom);
    
            menuBar.getMenus().add(menu);
    
            BorderPane borderPane = new BorderPane();
    
            borderPane.prefHeightProperty().bind(scene.heightProperty());
            borderPane.prefWidthProperty().bind(scene.widthProperty());
            
            borderPane.setTop(menuBar);
            
            root.getChildren().add(borderPane);
    
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    
        private EventHandler<ActionEvent> changeTabPlacement() {
            return new EventHandler<ActionEvent>() {
    
                public void handle(ActionEvent event) {
                    MenuItem mItem = (MenuItem) event.getSource();
                    String side = mItem.getText();
                    if ("left".equalsIgnoreCase(side)) {
                        System.out.println("left");
                    } else if ("right".equalsIgnoreCase(side)) {
                        System.out.println("right");
                    } else if ("top".equalsIgnoreCase(side)) {
                        System.out.println("top");
                    } else if ("bottom".equalsIgnoreCase(side)) {
                        System.out.println("bottom");
                    }
                }
            };
        }
    }
  • 相关阅读:
    mysql设置定时任务
    Spark On Yarn:提交Spark应用程序到Yarn
    Spark On Yarn:提交Spark应用程序到Yarn
    在Yarn上运行spark-shell和spark-sql命令行
    在Yarn上运行spark-shell和spark-sql命令行
    SparkSQL On Yarn with Hive,操作和访问Hive表
    SparkSQL On Yarn with Hive,操作和访问Hive表
    使用hive访问elasticsearch的数据
    使用hive访问elasticsearch的数据
    redis数据类型之list
  • 原文地址:https://www.cnblogs.com/rojas/p/4720258.html
Copyright © 2011-2022 走看看