javaFX学习之 Hello World

package sample;

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.FlowPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class HelloWorld extends Application {

    @Override
    public void start(Stage primaryStage) {//初始化舞台
        Text text = new Text();
        text.setFont(Font.font("SansSerif", FontWeight.BOLD, 24));//设置文本字体
        Button btn = new Button();
        btn.setText("点击");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                text.setText("点击按钮响应");
            }
        });

        FlowPane root = new FlowPane();//pane面板要加到场景scene对象上才能其效果
        root.getChildren().add(btn);//pane(面板,窗格)放在scene场景上才能其效果,而其他ui组件都是Node必须放在Pane上才能被看见
        root.getChildren().add(text);//pane(面板,窗格)放在scene场景上才能其效果,而其他ui组件都是Node必须放在Pane上才能被看见
        Scene scene = new Scene(root, 1200, 1000);//场景

        primaryStage.setTitle("hello world");
        primaryStage.setScene(scene);//scene必须放在stage舞台上才能被观赏(看见)
        primaryStage.show();//显示舞台才能可视化所有组件
    }

    public static void main(String[] args) {
        launch(args);//启动javaFX语句
    }
}

public class FlowPane extends Pane
public class Pane extends Region
public class Region extends Parent
public abstract class Parent extends Node

 

 

 

 

扩展阅读,  关于 javaFX编程还能做到哪些事情

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值