[英]No execution when javafx button pressed
My issue I am having is that when i click on my login in button it does nothing.我遇到的问题是,当我单击登录按钮时,它什么也不做。 There is no exceptions thrown and the try - catch doesnt seem to catch any errors/exceptions.
没有抛出异常,并且 try - catch 似乎没有捕获任何错误/异常。 Been looking through threads and have not found anything that works.
一直在寻找线程,并没有发现任何有效的东西。
I have added print statements throught out the code and it seems that is stops right at the start of the first try block, also added a stackTrace in both catch blocks and nothing我在整个代码中添加了打印语句,它似乎在第一个 try 块的开头就停止了,还在两个 catch 块中添加了一个 stackTrace,什么也没有
void getLoginAction(ActionEvent event) throws IOException, Exception {
String username = tfUsername.getText();
String password = tfPassword.getText();
loggingUsers.setUserName(username);
loggingUsers.setPassword(password);
FileHandler userFh = new FileHandler("UserLog.txt", true);
SimpleFormatter sf = new SimpleFormatter();
userFh.setFormatter(sf);
uLog.addHandler(userFh);
uLog.setLevel(Level.INFO);
try {
ObservableList<User> loginInfo = DatabaseMan.getActiveUsers();
loginInfo.forEach((u) -> {
try {
assert loggingUsers.getUserName().equals(u.getUserName()) && loggingUsers.getPassword().equals(u.getPassword()) : "Incorrect login info!";
loggingUsers.setUserId(u.getUserId());
try {
Appointment upcomingAppt = DatabaseAppointments.getUpcomingAppt();
if (!(upcomingAppt.getAppointmentId() == 0)) {
Alert apptAlert = new Alert(Alert.AlertType.INFORMATION);
apptAlert.setTitle("Upcoming Appointment Reminder");
apptAlert.setHeaderText("You have an upcoming appointment!");
apptAlert.setContentText("You have an appointment scheduled"
+ "\non " + upcomingAppt.getStart().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL))
+ "\nat " + upcomingAppt.getStart().format(DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL))
+ " with client " + upcomingAppt.getCustomer().getCustomerName() + ".");
apptAlert.showAndWait();
if (apptAlert.getResult() == ButtonType.OK) {
userLog.log(Level.INFO, "User: {0} logged in.", loggingUsers.getUserName());
Stage loginStage = (Stage) btnLogin.getScene().getWindow();
loginStage.close();
FXMLLoader apptCalLoader = new FXMLLoader(AppointmentCalendarController.class.getResource("MainAppointment.fxml"));
Parent calScreen = calLoader.load();
Scene calScene = new Scene(calScreen);
Stage calStage = new Stage();
calStage.setTitle("Appointment Calendar");
calStage.setScene(apptCalScene);
calStage.show();
}
else {
apptAlert.close();
}
}
else {
userLog.log(Level.INFO, "User: {0} logged in.", loggingUsers.getUserName());
FXMLLoader apptCalLoader = new FXMLLoader(AppointmentCalendarController.class.getResource("MainAppointment.fxml"));
Parent calScreen = calLoader.load();
Scene calScene = new Scenec(calScreen);
Stage calStage = new Stage();
calStage.setTitle("Appointment Calendar");
calStage.setScene(apptCalScene);
calStage.show();
Stage loginStage = (Stage) btnLogin.getScene().getWindow();
loginStage.close();
}
}
catch (IOException e) {
e.printStackTrace();
}
}
catch (AssertionError e) {
System.out.println(e.getMessage());
this.lblAlert.setText(this.rb.getString("lblErrorAlert") + ".");
this.lblAlert.setTextFill(Paint.valueOf("RED"));
userLog.log(Level.WARNING, "Invalid credentials entered! User: {0}", loggingUsers.getUserName());
}
});
}
catch (Exception e) {
e.printStackTrace();
}
}
no error messages and nothing happens when button is pressed按下按钮时没有错误消息并且没有任何反应
We gave up on the ActionEvent tagged onto our Button Clicks我们放弃了标记在按钮点击上的 ActionEvent
Here is how we name our Action Events and a code example这是我们如何命名动作事件和代码示例
The screen shot is from Scene Builder屏幕截图来自 Scene Builder
@FXML
private void onBack() throws IOException{
stage = (Stage)childTVPane.getScene().getWindow();// pane you are ON
paneStart = FXMLLoader.load(getClass().getResource("start.fxml"));// pane you are GOING TO
Scene scene = new Scene(paneStart);// pane you are GOING TO
scene.getStylesheets().add(getClass().getResource("diary.css").toExternalForm());
stage.setScene(scene);
stage.setTitle("Diary");
stage.show();
stage.sizeToScene();
stage.centerOnScreen();
}
Enjoy and Welcome to SO享受并欢迎来到 SO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.