1.显示一个最基本的框
package com.javafx01;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.scene.control.Label;
public class JavaFx01 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
//设置一个标签
Label label=new Label("Hello World");
//把标签放在一个根节点里面
BorderPane pane=new BorderPane(label);
//把根节点放在一个场景里面
Scene scene=new Scene(pane,300,300);
//场景设置到窗口
primaryStage.setScene(scene);
//窗口的标题
primaryStage.setTitle("我是窗口");
//显示窗口
primaryStage.show();
}
public static void main(String[] args) {
//启动应用程序
Application.launch(args);
}
}
2.框里有一个按钮,点击可以直接跳转自己所设定的网站
package com.javafx01;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class javafx02 extends Application {
public static void main(String[] args) {
//启动应用程序
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
//创建一个按钮
Button button=new Button("田茭");
//按钮放在布局里面
BorderPane pane=new BorderPane(button);
//跳转网站
button.setOnAction(a->{
getHostServices().showDocument("https://www.baidu.com/");
});
//把根节点放到一个场景里
Scene scene=new Scene(pane,300,300);
//把场景放到窗口里面
primaryStage.setScene(scene);
//窗口的标题
primaryStage.setTitle("javafx app");
//窗口的显示
primaryStage.show();
}
}
//设置窗口大小不变,默认是可以变 primaryStage.setResizable(false); //UNDECORATED窗口样式无装饰 primaryStage.initStyle(StageStyle.UNDECORATED);
3.多窗口
(1)APPLICATION_MODAL:全局模态
点开之后只有那个小窗口可以动,其他窗口无法点击
stage.initModality(Modality.APPLICATION_MODAL);
package com.javafx01;
import javafx.application.Application;
import javafx.scene.Sc