package D15; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class Demo15_7 extends Application{ public static void main(String[] args) { // TODO Auto-generated method stub Application.launch(args); } @Override public void start(Stage arg0) throws Exception { // TODO Auto-generated method stub Label a = new Label("用户名"); Label b = new Label("口令"); Button c = new Button("确定"); Button d = new Button("重置"); TextField wenben = new TextField(); PasswordField mima = new PasswordField(); TextArea wenbenqu = new TextArea(); GridPane pane = new GridPane(); pane.add(a, 0, 0); pane.add(b, 0, 1); pane.add(c, 0, 2); pane.add(d, 1, 2); pane.add(wenben, 1, 0); pane.add(mima, 1, 1); pane.add(wenbenqu, 0, 3, 2, 1); pane.setHgap(10); pane.setVgap(10); c.setOnAction(e->{ if(wenben.getText().equals("user") && mima.getText().equals("123456") ) wenbenqu.setText("欢迎登陆"); else wenbenqu.setText("用户名或密码错误"); }); d.setOnAction(e->{ wenben.clear(); mima.clear(); wenbenqu.setText("请输入用户名或密码"); }); Scene sc = new Scene(pane,500,200); arg0.setTitle("文本框"); arg0.setScene(sc); arg0.show(); } }将以上程序改进为登陆成功弹出一个新窗口
时间: 2023-12-06 16:43:22 浏览: 146
package D15;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Demo15_7 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Label a = new Label("用户名");
Label b = new Label("口令");
Button c = new Button("确定");
Button d = new Button("重置");
TextField wenben = new TextField();
PasswordField mima = new PasswordField();
TextArea wenbenqu = new TextArea();
GridPane pane = new GridPane();
pane.add(a, 0, 0);
pane.add(b, 0, 1);
pane.add(c, 0, 2);
pane.add(d, 1, 2);
pane.add(wenben, 1, 0);
pane.add(mima, 1, 1);
pane.add(wenbenqu, 0, 3, 2, 1);
pane.setHgap(10);
pane.setVgap(10);
c.setOnAction(e -> {
if (wenben.getText().equals("user") && mima.getText().equals("123456")) {
Stage newStage = new Stage();
Label successLabel = new Label("登录成功!");
VBox root = new VBox(successLabel);
Scene successScene = new Scene(root, 200, 100);
newStage.setScene(successScene);
newStage.setTitle("Success!");
newStage.show();
} else {
wenbenqu.setText("用户名或密码错误");
}
});
d.setOnAction(e -> {
wenben.clear();
mima.clear();
wenbenqu.setText("请输入用户名或密码");
});
Scene sc = new Scene(pane, 500, 200);
primaryStage.setTitle("文本框");
primaryStage.setScene(sc);
primaryStage.show();
}
}
阅读全文