javafx之登陆界面的跳转
界面布局用到的是fxml而非纯java代码,工具是javafx sence builder
账号:account 密码:password
登陆成功:
可以点击退出登陆返回到登陆页面
工程目录:
package check; /**
*
* @author itwang
*/
public class Check {
public static boolean checkreturn(String account,String password){
boolean checkbool = false;
if("account".equals(account)&&"password".equals(password)){
checkbool = true;
}
return checkbool;
}
}
package fxmltest; import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField; /**
*
* @author itwang
*/
public class LoginController implements Initializable {
@FXML private TextField account;
@FXML private PasswordField password;
private FXMLTest application; public void setApp(FXMLTest application){
this.application = application;
}
@FXML
public void LOGIN_M(ActionEvent event) {
application.userlogin(account.getText(), password.getText());
} @FXML
private void CLEAR_M(ActionEvent event) {
account.setText(null);
password.setText(null);
} @Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
package fxmltest; import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable; /**
*
* @author itwang
*/
public class MainController implements Initializable{
private FXMLTest application; public void setApp(FXMLTest application){
this.application = application;
} @FXML
private void OUT_M(ActionEvent event) {
application.useroutmain();
} @Override
public void initialize(URL url, ResourceBundle rb) { } }
package fxmltest; import check.Check;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage; /**
*
* @author itwang
*/
public class FXMLTest extends Application {
private Stage stage;
private final double MINIMUM_WINDOW_WIDTH = 400.0;
private final double MINIMUM_WINDOW_HEIGHT = 250.0; @Override
public void start(Stage primaryStage) throws Exception {
stage = primaryStage;
stage.setTitle("FXML Login Sample");
stage.setMinWidth(MINIMUM_WINDOW_WIDTH);
stage.setMinHeight(MINIMUM_WINDOW_HEIGHT);
gotologin();
stage.show();
}
public void gotologin(){
try {
LoginController login = (LoginController) replaceSceneContent("FXML_LOGIN.fxml");
login.setApp(this);
} catch (Exception ex) {
Logger.getLogger(FXMLTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void gotomain(){
try {
MainController main = (MainController) replaceSceneContent("FXML_MAIN.fxml");
main.setApp(this);
} catch (Exception ex) {
Logger.getLogger(FXMLTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void userlogin(String account,String password){
if(Check.checkreturn(account,password)){
gotomain();
}
}
public void useroutmain(){
gotologin();
}
private Initializable replaceSceneContent(String fxml) throws Exception {
FXMLLoader loader = new FXMLLoader();
InputStream in = FXMLTest.class.getResourceAsStream(fxml);
loader.setBuilderFactory(new JavaFXBuilderFactory());
loader.setLocation(FXMLTest.class.getResource(fxml));
AnchorPane page;
try {
page = (AnchorPane) loader.load(in);
} finally {
in.close();
}
Scene scene = new Scene(page, 800, 600);
stage.setScene(scene);
stage.sizeToScene();
return (Initializable) loader.getController();
}
public static void main(String[] args) {
launch(args);
}
}
<?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?> <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="400.0"
xmlns:fx="http://javafx.com/fxml" fx:controller="fxmltest.LoginController">
<children>
<VBox layoutX="3.0" layoutY="0.0" prefHeight="250.0" prefWidth="390.0" spacing="20.0">
<children>
<HBox minHeight="37.0" prefHeight="37.0" prefWidth="411.0">
<children>
<Label text="登陆界面">
<effect>
<DropShadow height="7.845238095238096" radius="4.1815476190476195" width="10.880952380952381" />
</effect>
<font>
<Font name="System Bold" size="30.0" />
</font>
<HBox.margin>
<Insets left="140.0" />
</HBox.margin>
</Label>
</children>
</HBox>
<GridPane alignment="TOP_RIGHT" prefWidth="380.0">
<children>
<Label alignment="TOP_RIGHT" text="Account" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="0">
<effect>
<DropShadow blurType="TWO_PASS_BOX" height="7.845238095238096" radius="3.675595238095238" width="8.857142857142858" />
</effect>
<font>
<Font size="25.0" fx:id="x1" />
</font>
<GridPane.margin>
<Insets right="8.0" fx:id="x2" />
</GridPane.margin>
</Label>
<Label font="$x1" text="password" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.margin="$x2" GridPane.rowIndex="1">
<effect>
<DropShadow blurType="TWO_PASS_BOX" height="7.845238095238094" radius="3.6755952380952372" width="8.857142857142854" />
</effect>
</Label>
<TextField fx:id="account" prefHeight="26.0" prefWidth="268.0" promptText="please input your account" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<PasswordField fx:id="password" prefWidth="223.0" promptText="please input your password" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button id="btn_login" mnemonicParsing="false" onAction="#LOGIN_M" prefWidth="80.0" text="登陆" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<effect>
<DropShadow />
</effect>
<GridPane.margin>
<Insets top="15.0" />
</GridPane.margin>
</Button>
<Button id="btn_clear" mnemonicParsing="false" onAction="#CLEAR_M" prefWidth="80.0" text="清除" GridPane.columnIndex="1" GridPane.rowIndex="2">
<effect>
<DropShadow />
</effect>
<GridPane.margin>
<Insets left="80.0" top="15.0" />
</GridPane.margin>
</Button>
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="205.0" minWidth="10.0" prefWidth="147.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="318.0" minWidth="10.0" prefWidth="243.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
<padding>
<Insets top="30.0" />
</padding>
</VBox>
</children>
</AnchorPane>
<?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?> <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"
xmlns:fx="http://javafx.com/fxml" fx:controller="fxmltest.MainController">
<children>
<Hyperlink layoutX="86.0" layoutY="111.0" text="退出登录!" onAction="#OUT_M">
<font>
<Font size="45.0" />
</font>
</Hyperlink>
</children>
</AnchorPane>
javafx之登陆界面的跳转的更多相关文章
- Ubuntu输入密码登陆后又跳回到登录界面
现象:在Ubuntu登陆界面输入密码之后,黑屏一闪并且出现了check battery state之类的文字之后,又跳转到登录界面.原因:主目录下的.Xauthority文件拥有者变成了root,从而 ...
- Ubuntu输入password登陆后又跳回到登录界面
现象:在Ubuntu登陆界面输入password之后.黑屏一闪而且出现了check battery state之类的文字之后,又跳转到登录界面. 原因:主文件夹下的.Xauthority文件拥有者变成 ...
- 在Ubuntu登陆界面输入密码之后,黑屏一闪后,又跳转到登录界面
现象:在Ubuntu登陆界面输入密码之后,黑屏一闪后,又跳转到登录界面.原因:主目录下的.Xauthority文件拥有者变成了root,从而以用户登陆的时候无法都取.Xauthority文件.说明:X ...
- Web 登陆界面---简单模块1
今天学习登陆界面的基本模块,其中几个基本的元素 a元素.form元素.布局元素(table\tr\td).加粗(b).input元素 1.<a href="">内容&l ...
- 解决 Ubuntu15.04 登陆界面无限循环 的问题
本人新手,在学习linux 安装NVIDIA 驱动的时候出现了一个奇怪的问题:登陆界面输入正确的账户密码,短暂闪烁后又返回了登陆界面.经查阅多种资料,已解决此问题 以下内容来自:http://blog ...
- Android 仿QQ微信开场导航以及登陆界面
相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后进入应 用,这一效果适用于多种项目中,相信今后开发应用一定会用得 ...
- Ubuntu 14.04 登陆界面循环问题解决
今天手贱startx然后虚拟机就卡死了,再开输过密码就无限跳到登陆界面,其他账户可用.怀疑/home未挂载. 解决方法:(alf改成你的用户名) $ cd ~$ sudo chown alf:alf. ...
- Shiro的FormAuthenticationFilter登陆成功不跳转
http://jinnianshilongnian.iteye.com/blog/2024723 张开涛的这个配置信息有误,导致默认authc登陆成功后无法跳转 FormAuthenticationF ...
- SpringSecurity自定义登陆页面和跳转页面
如果我们不用form-login说明登陆界面,springsecurity框架将自动为我们生成登陆界面 现在我们不想用自动生成的登陆界面了,而想使用自定义的漂亮的登陆界面 则需要使用<secur ...
随机推荐
- Nodejs学习总结
Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境.Node.js 使用了一个事件驱动.非阻塞式 I/O 的模型,使其轻量又高效. 官网 : http://node ...
- vim添加未识别文件类型
这里用.c的文件格式来识别.nc文件 $ cd ~/.vim/ftdetect $ vim nc.vim # nc.vim内容 # au BufRead,BufNewFilE *.nc set fil ...
- iOS - CoreData 数据库存储
1.CoreData 数据库 CoreData 是 iOS SDK 里的一个很强大的框架,允许程序员以面向对象的方式储存和管理数据.使用 CoreData 框架,程序员可以很轻松有效地通过面向对象的接 ...
- I2C总线(异步)
起始位与停止位的定义: 起始信号:当SCL为高期间,SDA由高到低的跳变:启动信号是一种电平跳变时序信号,而不是一个电平信号. 停止信号:当SCL为高期间,SDA由低到高的跳变:停止信号也是一种电平跳 ...
- Spring jar包详解
Spring jar包详解 org.springframework.aop ——Spring的面向切面编程,提供AOP(面向切面编程)的实现 org.springframework.asm——spri ...
- a.redhat系统如何卸载默认jdk
Redhat系统安装之后,会默认有openjdk在安装(下图已经是卸载掉了) 这个openjdk下面的需要进行卸载,你可以通过命令进行卸载,例如首先查看JDK,然后默认直接通过rpm命令进行卸载L 卸 ...
- Python之路 day2 字符编码及转换
#!/usr/bin/env python # -*- coding:utf-8 -*- #Author:ersa import sys print("sys default encodin ...
- [mysql] 记osx 10.10系统修改mysql root 密码
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html亲测方法3,已成功重置密码.(感谢@非常,告诉我官网就有重置方法,网上 ...
- zookeeper的zoo.cfg的配置
zookeeper的默认配置文件为zookeeper/conf/zoo_sample.cfg,需要将其修改为zoo.cfg.其中各配置项的含义,解释如下: tickTime:CS通信心跳时间 Zook ...
- [HTML/HTML5]1 HTML文档设置
1.1 创建HTML文件 本质上,HTML文件就是具有下列两个特征的简单文本文件: HTML文件的扩展名为.html或者.htm.文件扩展名是一个缩写,它可将文件正确地关联到需要访问它的程序或工具. ...