javafX初探(密码域)
2015-02-04 15:39
337 查看
本章我们介绍密码域的使用,典型的密码域如下图:
我们可以使用一个提示性的语句来,标识这是一个密码域,或者我们可以使用一个Label。当然密码域也有setText方法。我们可以使用这个方法为密码域赋值。但是密码域中的内容只显示点,不显示具体内容。
我们可以使用getText方法来获取用户输入的密码;
输入密码后,按回车键,如下图所示:
创建密码域
PasswordField passwordField = new PasswordField(); passwordField.setPromptText("Your password");
我们可以使用一个提示性的语句来,标识这是一个密码域,或者我们可以使用一个Label。当然密码域也有setText方法。我们可以使用这个方法为密码域赋值。但是密码域中的内容只显示点,不显示具体内容。
我们可以使用getText方法来获取用户输入的密码;
验证密码
package com.chu.button; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.stage.Stage; public class PasswordFiledTest extends Application { @Override public void start(Stage primaryStage) throws Exception { final Label message = new Label(""); VBox vb = new VBox(); vb.setPadding(new Insets(10, 0, 0, 10)); vb.setSpacing(10); HBox hb = new HBox(); hb.setSpacing(10); hb.setAlignment(Pos.CENTER_LEFT); Label label = new Label("Password"); final PasswordField pb = new PasswordField(); pb.setOnAction((ActionEvent e) -> { if (!pb.getText().equals("aaa")) { message.setText("Your password is incorrect!"); message.setTextFill(Color.rgb(210, 39, 30)); } else { message.setText("Your password has been confirmed"); message.setTextFill(Color.rgb(21, 117, 84)); } pb.clear(); }); hb.getChildren().addAll(label, pb); vb.getChildren().addAll(hb, message); Scene s = new Scene(vb,300,200); primaryStage.setScene(s); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
输入密码后,按回车键,如下图所示:
相关文章推荐
- javaFX初探(Camera)
- JavaFX初探(1)
- tommy_guolin JavaFX 2 初探----Eclipse下运行Ensemble程序
- 密码编码学初探——数论和有限域
- javafX初探(选择框)
- vba小收获---初探...解vbaproject密码
- javaFX初探(使用Image Ops API)
- javaFX初探(使用画布 API)
- javafX初探(单选按钮)
- JavaFx初探
- JavaFx初探(颜色选择器)
- JavaFx初探
- javafX初探(开关按钮)
- javafX初探(多选框)
- javafX初探(文本域)
- JavaFX初探(时间选择器)
- javaFX初探(部署)
- 初探druid 数据源加密,简单的密码加密。
- JavaFX初探与MediaPlayer(5)
- javaFX初探(灯光)