您好我正在创建一个登录页面和一个仪表板页面,我想关闭或隐藏我的登录页面,当我单击登录按钮时显示仪表板。但它不起作用
public class LoginController implements Initializable {
@FXML
private TextField txtUser;
@FXML
private PasswordField txtPassword;
@FXML
private Label message;
@FXML
private Label lblUser;
@FXML
private Label lblPassword;
@FXML
private void OpenDashBoard(ActionEvent event) {
try {
FxmlMethods object = new FxmlMethods();
// showFxml method usd for open a new window named DashBoard.fxml
object.showFxml("/DashBoard/DashBoard.fxml", "/ DashBoard/DashboardStyle.css", "Dash Board");
} catch (Exception exception) {
exception.printStackTrace();
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
我的主要课程是:
public class DATACOLLECTION extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Login.fxml"));
stage.getIcons().add(new Image("/images/icon.png"));
Scene scene = new Scene(root);
stage.setTitle("Login");
stage.setScene(scene);
scene.getStylesheets().addAll(this.getClass().getResource("Login.css").toExternalForm());
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
请帮帮我
答案 0 :(得分:2)
我正在使用它和它的工作感谢所有人的回应。
@FXML
private void CloseAction(ActionEvent event) {
Stage stage = (Stage) Close.getScene().getWindow();
stage.close();
}