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

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

<?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(); // 显示页面
}
}

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

JavaFXML实现新窗口打开的更多相关文章

  1. 如何用CSS实现在新窗口打开链接?

    *如何用CSS实现在新窗口打开链接? <style type="text/css"> <!-- .target2 a:active {test:expressio ...

  2. jQuery外链新窗口打开

    对于外链,为了留住用户在本站,我们通常会使用新窗口打开,你可以设置target="_blank".然而手动一个是麻烦,另一个则是有可能会遗漏,本文通过jQuery查询要点击的链接, ...

  3. HTML之:让网页中的<a>标签属性统一设置-如‘新窗口打开’

    在开发过程中,我们往往想在页面中,给<a>设置一个统一的默认格式,例如我们想让链接:“在新窗口打开”,我们就可以使用<base>标签 在网页中添加这段代码: <head& ...

  4. 如何在Flash中新窗口打开页面而不被拦截

    Flash的wmode必须是opaque或者transparent,允许Flash访问页面脚本.另外跳转必须是点击直接触发. 代码:ExternalInterface.call("windo ...

  5. javascript新窗口打开链接window.open()被阻拦的解决办法

    场景是ajax提交,比较后端效验数据,需要用户登录,提示后并需要新窗口打开登录的链接,使用window.open(url);往往会被浏览器认为是广告而被拦截. data.url是ajax返回的链接地址 ...

  6. jquery新窗口打开链接

    第一种:下面的代码是针对m35ui这个样式下的a都是在新窗口打开    <script type="text/javascript">  jQuery(document ...

  7. router-link 返回上页 和 新窗口打开链接

    1.如果使用了Vue-router的话,就可以用 this.$router.go(-1) 实现返回: 2.如果没使用vue-router,就可以用 window.history.go(-1) 实现返回 ...

  8. location.href 本窗口与window.open 新窗口打开用法

    二种新窗口打开的区别: window.open("URL",'top'); 只是表示打开这个页面,并不是打开并刷新页面: window.location.href="UR ...

  9. select中想要加a链接 并且新窗口打开

    //新窗口打开 <select id="" onchange="window.open(this.value)"> <option value ...

随机推荐

  1. 浅谈 .NET Framework 与 .NET Core 的区别与联系

    2017到了,咱们学点啥啊,要想知道学点啥,先弄清.NET Framework 与 .NET Core  这两个概念 .当今 net 生态系统如下: 从上面图中我们可以看到.net  主要分为三个部分 ...

  2. WCF寄宿在C#控制台,并用命令行启动

    公司运用wcf比较多,所以自己研究一下寄宿做个笔记,wcf寄宿在控制台有两种方式 第一种,直接在控制台程序内添加wcf服务. 第二种分别添加控制台程序和wcf服务应用程序,前者引用后者,并在app.c ...

  3. Android界面编程--使用活动条(ActionBar)--添加Action View

    ActionBar除了显示Action Item 外,还能显示普通的ui组件 2种方式添加Action View 1.指定ActionView的实现类 2.指定ActionView对应的视图资源 实现 ...

  4. hdu 1394 逆序数(线段树)

    http://acm.hust.edu.cn/vjudge/problem/15764 http://blog.csdn.net/libin56842/article/details/8531117 ...

  5. 用于模式匹配的String方法和RegExp方法

    上一节总结了创建正则表达式的语法,这一篇笔者总结了用于模式匹配的String四个方法:search().replace().match().split()以及用于模式匹配的RegExp两个方法exec ...

  6. 阿里云服务器Linux常用命令

    系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...

  7. vue 音乐播放器报错

    使用Vue报错[Vue warn]: Error in nextTick: "TypeError: fn.bind is not a function"页面进不去. 检查:看看da ...

  8. ArcGIS软件操作——地图制图

    ArcGIS软件操作系列二(地图制图) 2016年毕业,参加工作,除了平时出差,大部分时间都在使用ArcGIS处理数据.制图,在此,先将一些制图的小心得撰写出来,希望能与各位共同交流. 1 数据准备: ...

  9. Multidex (方法数超过限制的处理)

    报错 : Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536 ...

  10. pnp4nagios 性能调优

    http://popozhu.github.io/2014/03/12/pnp4nagios%E7%9A%84%E5%B9%B6%E5%8F%91/ rrd目录分层 bulk模式 修改模板 修改/pr ...