Preface
方法:初始的stage方法一样,没有任何的区别
此处,为了部分(偷懒的)同学方便,给出实例,实则非常简单。
核心的内容是在Controller.java中
@FXML
private void newButtonOnClicked(){
try {
//一定需要使用try-catch,不然编译器不会让你过的,Trust me!
Parent anotherRoot = FXMLLoader.load(getClass().getResource("sample.fxml"));
Stage anotherStage = new Stage();
anotherStage.setTitle("Another Window Triggered by Clicking");
anotherStage.setScene(new Scene(anotherRoot, 600, 329));
anotherStage.show();
} catch (Exception e){
e.printStackTrace();
}
}
代码
代码结构
sample
├── Controller.java
├── main.fxml
├── Main.java
└── sample.fxml
Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override