我的第一个JavaFX程序

来源:互联网 发布:淘宝 购物 编辑:程序博客网 时间:2024/06/06 16:26

由于一直想做一个可以跨WINDOW和MAC系统的桌面应用,考虑过PYTHON,但是PYTHON虽然方便,但是他的界面实在不敢恭维,由于之前了解的比较多的是Java,Android,Javascript,Html,用JavaFX就相对比较容易上手,而JavaFX做出来的界面是非常漂亮炫酷,而且非常灵活,功能也超强大,其实感觉和Android的开发模式风格非常类似。


用NetBeans开发环境,新建一个JavaFX项目就会自动生成一个HelloWorld的例程:


package javafxapplication3;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.layout.StackPane;import javafx.stage.Stage;/** * * @author Administrator */public class JavaFXApplication3 extends Application {        @Override    public void start(Stage primaryStage) {        Button btn = new Button();        btn.setText("欢迎来到易千忆学堂'");        btn.setOnAction(new EventHandler<ActionEvent>() {                        @Override            public void handle(ActionEvent event) {                System.out.println("Hello World!");            }        });                StackPane root = new StackPane();        root.getChildren().add(btn);                Scene scene = new Scene(root, 800, 400);                primaryStage.setTitle("易千忆学堂");        primaryStage.setScene(scene);        primaryStage.show();    }    /**     * @param args the command line arguments     */    public static void main(String[] args) {        launch(args);    }    }

0 0