JavaFXML实现新窗口打开
实现原理顺着往下看就明白了,流程看红色字体。具体还有什么问题可以留言。
主页面配置文件,一共三个按钮。这里说明第一个按钮触发打开新窗口
<?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实现新窗口打开的更多相关文章
- 如何用CSS实现在新窗口打开链接?
*如何用CSS实现在新窗口打开链接? <style type="text/css"> <!-- .target2 a:active {test:expressio ...
- jQuery外链新窗口打开
对于外链,为了留住用户在本站,我们通常会使用新窗口打开,你可以设置target="_blank".然而手动一个是麻烦,另一个则是有可能会遗漏,本文通过jQuery查询要点击的链接, ...
- HTML之:让网页中的<a>标签属性统一设置-如‘新窗口打开’
在开发过程中,我们往往想在页面中,给<a>设置一个统一的默认格式,例如我们想让链接:“在新窗口打开”,我们就可以使用<base>标签 在网页中添加这段代码: <head& ...
- 如何在Flash中新窗口打开页面而不被拦截
Flash的wmode必须是opaque或者transparent,允许Flash访问页面脚本.另外跳转必须是点击直接触发. 代码:ExternalInterface.call("windo ...
- javascript新窗口打开链接window.open()被阻拦的解决办法
场景是ajax提交,比较后端效验数据,需要用户登录,提示后并需要新窗口打开登录的链接,使用window.open(url);往往会被浏览器认为是广告而被拦截. data.url是ajax返回的链接地址 ...
- jquery新窗口打开链接
第一种:下面的代码是针对m35ui这个样式下的a都是在新窗口打开 <script type="text/javascript"> jQuery(document ...
- router-link 返回上页 和 新窗口打开链接
1.如果使用了Vue-router的话,就可以用 this.$router.go(-1) 实现返回: 2.如果没使用vue-router,就可以用 window.history.go(-1) 实现返回 ...
- location.href 本窗口与window.open 新窗口打开用法
二种新窗口打开的区别: window.open("URL",'top'); 只是表示打开这个页面,并不是打开并刷新页面: window.location.href="UR ...
- select中想要加a链接 并且新窗口打开
//新窗口打开 <select id="" onchange="window.open(this.value)"> <option value ...
随机推荐
- 深入理解JavaScript系列(6):S.O.L.I.D五大原则之单一职责SRP
前言 Bob大叔提出并发扬了S.O.L.I.D五大原则,用来更好地进行面向对象编程,五大原则分别是: The Single Responsibility Principle(单一职责SRP) The ...
- 很有用的PHP笔试题系列二
1.如何用php的环境变量得到一个网页地址的内容?ip地址又要怎样得到? Gethostbyname() echo $_SERVER ["PHP_SELF"];echo $_SER ...
- ASP.NET 使用 AjaxPro 实现前端跟后台交互
使用 AjaxPro 进行交互,很多人都写过文章了,为什么还要继续老生常谈呢.因为有一些细节上的东西我们需要注意,因为这些细节如果不注意的话,那么程序会报错,而且维护性较差. 引言 一.首先,还是那句 ...
- Visual Paradigm for UML 10.0 SP1 企业中文下载地址、安装及激活详解教程
https://blog.csdn.net/u013354805/article/details/46531833
- LI居中
在用UL-LI时,有适合需要将Li里面的内容居中显示:方法有两种:(推荐)1.设置LI的display为inline(规定应该从父元素继承 display 属性的值),为LI设置长度,设置text-a ...
- CSS的两种格式化上下文:BFC和IFC
CSS的两种格式化上下文 文章包含很多个人理解,如果错误,欢迎指出~ 在看本文之前,你要对CSS的盒子模型,Block-Level元素,Inline-Level元素有所了解,具体可参考CSS的 ...
- 使用 iframe + postMessage 实现跨域通信
在实际项目开发中可能会碰到在 a.com 页面中嵌套 b.com 页面,这时第一反应是使用 iframe,但是产品又提出在 a.com 中操作,b.com 中进行显示,或者相反. 1.postMess ...
- twaver拓扑图通道组织图(百分比使用率/水槽)效果实现
功能介绍: 利用拓扑图实现:64条通道,根据每条通道是否承载业务,提供百分比展示 首先上图,功能效果如图: 废话不多,直接上代码: <!DOCTYPE html> <html> ...
- Android 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏
private void showMyDialog(int layoutId){ AlertDialog myDialog = new AlertDialog.Builder(context).cre ...
- CSS3布局样式
CSS3多列布局columns 为了能在Web页面中方便实现类似报纸.杂志那种多列排版的布局,W3C特意给CSS3增加了一个多列布局模块(CSS Multi Column Layout Module) ...