package cn.learn.filewriter;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Filewriter extends Application {
private Stage stage = new Stage();
private Stage stage1 = new Stage();
private Stage stage2 = new Stage();
private final int SCREENWIDTH = 333;
private final int SCREENHEIGHT = 300;
public void start(Stage primaryStage) {
GridPane borderPane = new GridPane();
Button btBack = new Button("OK");
Text text=new Text("Stage");
borderPane.add(btBack, 0, 0);
borderPane.add(text, 0, 1);
Scene scene = new Scene(borderPane, SCREENWIDTH, SCREENHEIGHT);
stage.setScene(scene);
stage.setTitle("Bank");
stage.show();
btBack.setOnAction(e -> fun1());
}
public void fun1() {
GridPane borderPane = new GridPane();
Button btBack = new Button("Back");
Button btOk=new Button("OK");
Text text=new Text("Stage1");
borderPane.add(btBack, 5, 5);
borderPane.add(btOk, 1, 5);
borderPane.add(text, 0, 1);
Scene scene = new Scene(borderPane, SCREENWIDTH, SCREENHEIGHT);
stage1.setScene(scene);
stage1.setTitle("Bank");
stage1.show();
btOk.setOnAction(e->fun2());
}
public void fun2() {
GridPane borderPane = new GridPane();
Button btBack = new Button("Back");
Text text=new Text("Stage2");
borderPane.add(btBack, 0, 0);
borderPane.add(text, 0, 1);
Scene scene = new Scene(borderPane, SCREENWIDTH, SCREENHEIGHT);
stage2.setScene(scene);
stage2.setTitle("Bank");
stage2.show();
btBack.setOnAction(e -> start(stage1));
}
public static void main(String[] args) {
Application.launch(args);
}
}
比如这段代码
我想Stage2的back回到Stage1
应该怎么实现?
谢谢大家!