实现原理顺着往下看就明白了,流程看红色字体。具体还有什么问题可以留言。

主页面配置文件,一共三个按钮。这里说明第一个按钮触发打开新窗口

<?xml version="1.0" encoding="UTF-8"?>

<!--导入JavaFXML类-->
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?> <!--布局控件BorderPane,fx:controller属性用于声明事件处理的Controller,值为Controller类的类全名-->
<!--xmlns用于声明默认命名空间,这里的声明随着你安装的Java JDK版本号的不同可以不同,但是最好不要比你安装的JDK版本高-->
<BorderPane fx:controller="APP.mainController" xmlns="http://javafx.com/javafx/8.0.31" xmlns:fx="http://javafx.com/fxml/1">
<center>
<VBox fx:id="vBox" alignment="CENTER" spacing="25" >
<Button fx:id="b1" text="FOO管理" onAction="#fooButtonAction">
<font>
<Font name="Times New Roman" size="15" />
</font>
</Button>
<Button fx:id="b2" text="Goods管理" onAction="#goodhandleButtonAction">
<font>
<Font name="Times New Roman" size="15" />
</font>
</Button>
<Button fx:id="b3" text="统计检索" onAction="#searchhandleButtonAction">
<font>
<Font name="Times New Roman" size="15" />
</font>
</Button> </VBox>
</center>
</BorderPane>

主页面的控制类

package APP;

import java.io.IOException;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button; public class mainController { @FXML
private Button b1;
@FXML
private Button b2;
@FXML
private Button b3;
@FXML
protected void fooButtonAction(ActionEvent event) throws IOException { FooPane.showFooPane(); }
@FXML
protected void goodhandleButtonAction(ActionEvent event) throws IOException { GoodsPane.showFooPane(); }
@FXML
protected void searchhandleButtonAction(ActionEvent event) throws IOException { searchPane.showFooPane();
} }

主页面启动类

package APP;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage; public class MainPaneFxml extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
try {
BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("main.fxml"));
Scene scene = new Scene(root, 500, 250);
primaryStage.setScene(scene);
primaryStage.setTitle("主程序");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Application.launch(args);
}
}

点击第一个按钮以后打开的窗口的配置文件

<?xml version="1.0" encoding="UTF-8"?>

<!--导入JavaFXML类-->
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?> <!--布局控件BorderPane,fx:controller属性用于声明事件处理的Controller,值为Controller类的类全名-->
<!--xmlns用于声明默认命名空间,这里的声明随着你安装的Java JDK版本号的不同可以不同,但是最好不要比你安装的JDK版本高-->
<BorderPane fx:controller="APP.FooController" xmlns="http://javafx.com/javafx/8.0.31" xmlns:fx="http://javafx.com/fxml/1">
<center>
<GridPane alignment="center" hgap="5" vgap="10">
<children>
<Label text="姓名" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<TextField fx:id="fName" GridPane.columnIndex="1" GridPane.rowIndex="0" alignment="center_right"/> <Label text="身份证" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<TextField fx:id="fIDcard" GridPane.columnIndex="1" GridPane.rowIndex="1" alignment="center_right"/> <Label text="省" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
<TextField fx:id="fProvince" GridPane.columnIndex="1" GridPane.rowIndex="2" alignment="center_right"/> <Label text="市" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<TextField fx:id="fCity" GridPane.columnIndex="1" GridPane.rowIndex="3" alignment="center_right"/> <Label text="乡" GridPane.columnIndex="0" GridPane.rowIndex="4"/>
<TextField fx:id="fTown" GridPane.columnIndex="1" GridPane.rowIndex="4" alignment="center_right"/> <Label text="村" GridPane.columnIndex="0" GridPane.rowIndex="5"/>
<TextField fx:id="fVillage" GridPane.columnIndex="1" GridPane.rowIndex="5" alignment="center_right"/> <Button fx:id="b1" text="导出FOO为HTML封装" onAction="#htmlButtonAction" GridPane.columnIndex="0" GridPane.rowIndex="6"> <font>
<Font name="Times New Roman" size="15" />
</font>
</Button>
<Button fx:id="b2" text="导出FOO为XML封装" onAction="#xmlButtonAction" GridPane.columnIndex="1" GridPane.rowIndex="6"> <font>
<Font name="Times New Roman" size="15" />
</font>
</Button> </children>
</GridPane>
</center>
</BorderPane>

点击第一个按钮以后出发的操作

@FXML
protected void fooButtonAction(ActionEvent event) throws IOException { FooPane.showFooPane(); }

上述方法里类的源代码。在这个类里面加载了新窗口的配置文件

package APP;

import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage; public class FooPane extends AnchorPane {
private static FooPane fooPane;
private Stage stage;
// 构造方法:私有
private FooPane() {
try {
BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("FOO.fxml"));
stage = new Stage();
stage.setTitle("FOO管理");
stage.setScene(new Scene(root, 500, 250));
} catch (IOException ex) {
ex.printStackTrace();
}
}
public Stage getStage() {
return this.stage;
}
// 外部调用方法
public static void showFooPane() {
fooPane = new FooPane(); // 构造实例
fooPane.getStage().show(); // 显示页面
}
}

上述是没有数据交互的打开新窗口,如果想在打开新窗口的同时初始化新窗口页面显示的内容,评论区留言。

最新文章

  1. 在本机搭建SVN服务器
  2. 理解autorelease
  3. sphinx 增量索引 实现近实时更新
  4. systemtap
  5. 一个Azure VM RDP连接问题
  6. bzoj 3283: 运算器 扩展Baby Step Giant Step &amp;&amp; 快速阶乘
  7. WPF自定义窗体仿新毒霸关闭特效(只能在自定义窗体中正常使用)
  8. hadoop-2.0.0-mr1-cdh4.2.0源码编译总结
  9. iOS知识点全梳理-备用
  10. lua 安装配置
  11. bootstrap标准模板
  12. Dynamics CRM中一个查找字段引发的【血案】
  13. 持续集成-jenkins介绍与环境搭建
  14. mysql性能优化分析 --- 上篇
  15. Centos7中在线/离线安装DockerCE最新版
  16. Html5 postMessage实现跨域消息传递
  17. imx6ul linux4.1.15 LED驱动配置及heartbeat源码分析【转】
  18. Jmeter(二十)Beanshell or JSR223
  19. JVM的參數
  20. normalize.css 中文版

热门文章

  1. jquery点滴总结
  2. js中的encodeURIComponent()函数
  3. ionic2 目录
  4. solidity数据类型
  5. (三)PHP网页架站
  6. [LeetCode]24. Swap Nodes in Pairs两两交换链表中的节点
  7. 数据库中char、varchar、varchar2、nvarchar之间的关系
  8. ahp层次分析法软件
  9. 爬楼梯C++
  10. 网络威胁防护,Azure 靠的是它?