admin管理员组文章数量:1794759
JavaFX
登录账号和密码使用的不是数据库,是使用
setUserData("a");//给一个测试数据
注入的测试数据,效果就是登陆成功后进入界面显示登录账号和密码,失败后登录窗口闪烁进行提示。
package sample;import com.sun.org.apache.bcel.internal.generic.NEW;
import javafx.animation.FadeTransition;
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.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;public class Main extends Application {public static void main(String[] args) {launch(args);}@Overridepublic void start(Stage primaryStage) throws Exception {Button b3 = new Button("b3");Button b4 = new Button("b4");Label l_name = new Label("名字:");l_name.setFont(new Font(20));//字体大小l_name.setTooltip(new Tooltip("请输入名字"));Label l_pswd = new Label("密码:");l_pswd.setTooltip(new Tooltip("请输入密码"));l_pswd.setFont(new Font(20));TextField t_name = new TextField();t_name.setUserData("a");//给一个测试数据PasswordField p_pswd = new PasswordField();p_pswd.setUserData("aa");//给一个测试数据Button login = new Button("登录");Button clear = new Button("清除");GridPane gr = new GridPane();gr.setStyle("-fx-background-color: #efead0");gr.add(l_name, 0, 0);gr.add(t_name, 1, 0);gr.add(l_pswd, 0, 1);gr.add(p_pswd, 1, 1);gr.add(clear, 0, 2);gr.add(login, 1, 2);gr.setAlignment(Pos.CENTER);gr.setHgap(10);//设置水平间距gr.setVgap(17);//设置垂直间距GridPane.setMargin(login, new Insets(0, 0, 0, 120));//清除事件clear.setOnAction(new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent event) {t_name.setText("");p_pswd.setText("");//变空或者p.clear}});//登录事件login.setOnAction(new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent event) {String name = t_name.getText();String pswd = p_pswd.getText();if (t_name.getUserData().equals(name) && p_pswd.getUserData().equals(pswd)) {//和up写的不太一样System.out.println("登陆成功!");mywindow MWD = new mywindow(name, pswd);primaryStage.close();} else {System.out.println("登录失败!");l_name.setTextFill(Color.CORAL);FadeTransition tst = new FadeTransition();tst.setDuration(Duration.seconds(0.2));tst.setNode(gr);tst.setFromValue(0);tst.setToValue(1);tst.play();}}});Scene scene = new Scene(gr);primaryStage.setScene(scene);primaryStage.setTitle("Java FX - 登录页面 ");primaryStage.setWidth(500);primaryStage.setHeight(300);primaryStage.setResizable(false); //登录窗口的大小不允许改变primaryStage.show();}}class mywindow {private final Stage stage = new Stage();public mywindow(String name, String password) {Text text = new Text("账号:" + name + " 密码" + password);BorderPane bor = new BorderPane();bor.setStyle("-fx-background-color: cadetblue");bor.setCenter(text);Scene scene = new Scene(bor);stage.setScene(scene);stage.setTitle("登陆成功 ");stage.setWidth(500);stage.setHeight(500);stage.setResizable(false); //登录窗口的大小不允许改变stage.show();}
}
本文标签: Javafx
版权声明:本文标题:JavaFX 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1692486534a138125.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论