JavaFX 使用实例
来源:互联网 发布:pop3协议默认端口号 编辑:程序博客网 时间:2024/06/06 00:08
附上官方例子:http://docs.oracle.com/javase/8/javafx/sample-apps/
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package login;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.geometry.Insets;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.control.Label;import javafx.scene.control.PasswordField;import javafx.scene.control.TextField;import javafx.scene.layout.GridPane;import javafx.scene.layout.HBox;import javafx.scene.paint.Color;import javafx.scene.text.Font;import javafx.scene.text.FontWeight;import javafx.scene.text.Text;import javafx.stage.Stage;import javax.swing.JOptionPane;/** * * @author Administrator */public class Login extends Application { @Override public void start(Stage primaryStage) throws Exception { String title = "javafx welcome to login! h=" + String.valueOf((int) primaryStage.getHeight()) + ",w=" + String.valueOf((int) primaryStage.getWidth()); System.out.println(title); System.out.println(primaryStage.getWidth()); if (Double.isNaN(primaryStage.getHeight())) { System.out.println("is nan"); } else { System.out.println("not is nan"); } //primaryStage.setWidth(500); // primaryStage.setHeight(500); primaryStage.setTitle(title); GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setHgap(10); gridPane.setVgap(10); gridPane.setPadding(new Insets(25, 25, 25, 25)); Scene scene = new Scene(gridPane, 300, 300); primaryStage.setScene(scene); Text sceneTitle = new Text("Welcome"); sceneTitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); gridPane.add(sceneTitle, 0, 0, 2, 1); Label userName = new Label("User Name:"); gridPane.add(userName, 0, 1); final TextField userTextField = new TextField(); gridPane.add(userTextField, 1, 1); Label pw = new Label("Password:"); gridPane.add(pw, 0, 2); final PasswordField pwdBox = new PasswordField(); gridPane.add(pwdBox, 1, 2); Button btn = new Button("Sign in"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().add(btn); gridPane.add(hbBtn, 1, 4); final Text actiontarget = new Text(); gridPane.add(actiontarget, 1, 6); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { actiontarget.setFill(Color.FIREBRICK); actiontarget.setText("Sign in button pressed"); String userString=userTextField.getText(); String passwordString=pwdBox.getText(); if(userString!=null && userString.equals("admin")&&passwordString!=null&&passwordString.equals("123456")) { JOptionPane.showMessageDialog(null, "登陆成功!"); }else{ JOptionPane.showMessageDialog(null, "登陆失败,账号密码不正确!"); } } }); primaryStage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); }}
0 0
- JavaFX 使用实例
- JavaFX DirectoryChooser[目录选择器]使用实例及源代码[图文]
- JavaFX的:入门使用JavaFX
- JavaFX Application应用实例
- JavaFx 使用有感
- JavaFX - 使用UI控件
- JavaFX 使用FAQ
- 使用JavaFx实现拼图游戏
- MyEclipse10使用JavaFX
- JavaFX的ResourceBundle使用
- javaFX 使用进度条
- javafx中radiobutton使用
- javaFX 的入门使用
- JavaFX菜单ContextMenu使用
- javafx的基本控件实例代码
- JavaFX中实例化Java类对象
- javaFX实例1-webView实现简单浏览器
- JAVAFX:使用声明性语法
- android控件显示顺序控制
- 在Unity3D中使用ScriptableObject进行序列化
- Cocos2d-x下Lua调用自定义C++类和函数的最佳实践
- JAVA操作properties文件
- 《Deep Learning Face Representaion from Predicting 10000 Classes》读书报告
- JavaFX 使用实例
- android-eventbus
- c/c++内存分配与内存对齐全面探讨
- 使用C#获取当前Windows所设定的时区
- .proto文件转.cs的方法
- log4j日志等级 .
- 【学习OpenCV】编程笔记:一些需要注意的细节
- Js:Js 对象——概述
- Linux内存管理初探