[英]Stage won't open even though the code runs in javafx
So, I made this simple code and it doesn't show any error or warnings, but for some reason, when I press run, it doesn't open a window.所以,我做了这个简单的代码,它没有显示任何错误或警告,但由于某种原因,当我按下运行时,它没有打开 window。 I'm not sure where it went wrong.我不确定哪里出错了。 The point of the code is to show a simple text depending on who tries to log in. I'm going to expand it later and add new things to it, but for now it just needs to run as it is.代码的重点是根据谁尝试登录来显示一个简单的文本。我稍后将对其进行扩展并向其中添加新内容,但现在它只需要按原样运行即可。 Here's the code:这是代码:
public class LogIn extends Application {
Users Cashier = new Users("Filan", "Fisteku", "ffisteku@gmail.com", 500, 1, "0691234567", "15/01/2000", "open");
Users Manager = new Users("Mario", "Rossi", "mrossi@gmail.com", 750, 2, "0681234567", "09/08/1995", "lararossi");
Users Administrator = new Users("John", "Doe", "jdoe1980@gmail.com", 1000, 3, "0697654321", "11/11/1980",
"password");
public void start(final Stage stage) {
// Creating nodes
final TextField txtField = new TextField();
final PasswordField pwField = new PasswordField();
final Button button = new Button("LOGIN");
button.setTranslateX(250);
button.setTranslateY(75);
// Creating labels
final Label label1 = new Label("Email: ");
final Label label2 = new Label("Password: ");
// Setting the message with read data
final Text text = new Text("");
Font font = Font.font("Comic Sans", FontWeight.BOLD, FontPosture.REGULAR, 10);
text.setFont(font);
text.setTranslateX(15);
text.setTranslateY(125);
text.setFill(Color.BLACK);
// Displaying the message
button.setOnAction(new EventHandler() {
public void handle(Event e) {
// Retrieving data
final String email = txtField.getText();
final String pw = pwField.getText();
if (email.equals(Cashier.email) && pw.equals(Cashier.password)) {
text.setText("Hello " + Cashier.name + " " + Cashier.lastname + ". Welcome!");
}
if (email.equals(Manager.email) && pw.equals(Manager.password)) {
text.setText("Hello " + Manager.name + " " + Manager.lastname + ". Welcome!");
}
if (email.equals(Administrator.email) && pw.equals(Administrator.password)) {
text.setText("Hello " + Administrator.name + " " + Administrator.lastname + ". Welcome!");
}
// Adding labels for nodes
HBox box = new HBox(5);
box.setPadding(new Insets(25, 5, 5, 50));
box.getChildren().add(label1);
box.getChildren().add(txtField);
box.getChildren().add(label2);
box.getChildren().add(pwField);
Group root = new Group();
root.getChildren().add(box);
// Setting the stage
Scene scene = new Scene(root, 500, 250, Color.SILVER);
stage.setTitle("LogIn Site for Tech Store");
stage.setScene(scene);
stage.show();
}
}
);
;
;
;
;
}
public static void main(String args[]) {
launch(args);
}
}
Your code,你的代码,
// Setting the stage
Scene scene = new Scene(root, 500, 250, Color.SILVER);
stage.setTitle("LogIn Site for Tech Store");
stage.setScene(scene);
stage.show();
should come out of the EventHandler
method
.应该从EventHandler
method
中出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.