package com.example.multiwindown;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class MainClass extends Application {
//主窗口
private Stage primaryStage;
//主控制器
private PrimaryController primaryController;
//start阶段进行初始化
@Override
public void start(Stage stage) throws IOException {
primaryStage = stage;
this.showPrimaryStage();
}
public void showPrimaryStage() {
FXMLLoader fxmlLoader = new FXMLLoader(MainClass.class.getResource("primaryView.fxml"));
Scene scene = null;
try {
scene = new Scene(fxmlLoader.load(), 800, 600);
} catch (IOException e) {
e.printStackTrace();
}
PrimaryController controller = fxmlLoader.getController();
//-------------------------------------------------
controller.setMain(this);
//-------------------------------------------------
this.primaryController = controller;
primaryStage.setTitle("Hello!");
primaryStage.setScene(scene);
primaryStage.show();
}
//打开新窗口
public void openNewStage() {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("newStageView1.fxml"));
Scene scene = new Scene(fxmlLoader.load());
NewStageController controller = fxmlLoader.getController();
Stage newStage = new Stage();
newStage.setScene(scene);
newStage.setTitle("新的窗体");
//------------------------------------------------
controller.setMain(this, newStage);
//------------------------------------------------
newStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//切换主窗口的Scene
public void changePrimaryScene() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("newSceneView.fxml"));
Scene scene = new Scene(loader.load());
NewSceneController controller = loader.getController();
//-------------------------------------------
controller.setMain(this);
//---------------------------------------
primaryStage.setScene(scene);
} catch (IOException e) {
e.printStackTrace();
}
}
//打开展示信息窗口
public void openSendStage(String msg) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("showMsgView.fxml"));
Scene scene = new Scene(fxmlLoader.load());
Stage stage = new Stage();
ShowMsgController controller1 = fxmlLoader.getController();
//---------------------------------------------
controller1.init(this, stage);
//----------------------------------------------
controller1.showMessage(msg);
stage.setScene(scene);
stage.setTitle("show msg window");
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//打开发送窗口
public void openReceiveStage() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("receiveMsgView.fxml"));
Scene scene = new Scene(loader.load());
Stage stage = new Stage();
ReceiveMsgController controller = loader.getController();
//-------------------------------------------------------
controller.init(this.primaryController, stage);
//-------------------------------------------------------
stage.setScene(scene);
stage.setTitle("send Message");
stage.show();
}
public static void main(String[] args) {
launch();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
multiWindown.zip (14个子文件)
multiWindown
pom.xml 3KB
src
main
resources
META-INF
MANIFEST.MF 79B
com
example
multiwindown
newSceneView.fxml 701B
newStageView1.fxml 448B
primaryView.fxml 1KB
showMsgView.fxml 518B
receiveMsgView.fxml 519B
java
module-info.java 182B
com
example
multiwindown
ReceiveMsgController.java 649B
NewStageController.java 872B
MainClass.java 4KB
PrimaryController.java 1KB
NewSceneController.java 370B
ShowMsgController.java 537B
共 14 条
- 1
资源评论
追光少年3322
- 粉丝: 166
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功