如何从JavaFX中的其他类调用 start 方法?我以这种方式尝试过,但没有成功!顺便说一下,我是JavaFX的新手。
public class LoginWindow extends Application {
private Stage window ;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
window = primaryStage ;
window.setTitle("Login");
GridPane grid = new GridPane() ;
grid.setPadding(new Insets(10 , 10 ,10 ,10));
grid.setAlignment(Pos.CENTER);
grid.setVgap(8);
grid.setHgap(10);
Label usernameL = new Label("Username : ") ;
GridPane.setConstraints(usernameL , 0 , 0);
Label passwordL = new Label("Password : ") ;
GridPane.setConstraints(passwordL,0 ,2 );
TextField username = new TextField() ;
username.setPromptText("username"); ;
GridPane.setConstraints(username , 1 , 0);
TextField password = new TextField() ;
password.setPromptText("password");
GridPane.setConstraints(password,1,2); ;
Button login = new Button("Login") ;
GridPane.setConstraints(login , 1 , 3);
login.setOnAction(e -> {
HomeWindow homeW = new HomeWindow();
homeW.start(HomeWindow.stage);
window.close();
});
grid.getChildren().addAll(usernameL,passwordL,username,password,login);
Scene s1 = new Scene(grid,1200,800) ;
window.setScene(s1);
window.show();
}
}
那是另一类:
public class HomeWindow extends Application {
public static Stage stage ;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
stage = primaryStage ;
stage.setTitle("Home");
stage.setMaximized(true);
Label welcome = new Label("You logged sucessefully ") ;
StackPane layout = new StackPane() ;
layout.getChildren().add(welcome) ;
welcome.setAlignment(Pos.CENTER);
Scene sc = new Scene(layout) ;
stage.setScene(sc);
stage.show();
}
}
有关其他任何详细信息,请随时问我!
由于没有添加太多细节而无法发布我的问题,因此我被迫写下这些句子:(