为了账号安全,请及时绑定邮箱和手机立即绑定

按下 javafx 按钮时不执行

按下 javafx 按钮时不执行

白衣非少年 2023-11-01 22:48:27
我遇到的问题是,当我单击“登录”按钮时,它什么也没做。没有抛出异常,并且 try - catch 似乎没有捕获任何错误/异常。一直在浏览线程,但没有发现任何有效的东西。我在整个代码中添加了 print 语句,似乎在第一个 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() + ".");                            }没有错误消息,按下按钮时没有任何反应
查看完整描述

1 回答

?
长风秋雁

TA贡献1757条经验 获得超7个赞

我们放弃了标记到按钮点击上的 ActionEvent
这是我们命名 Action Event 的方式和代码示例 屏幕截图来自 Scene Builder

https://img1.sycdn.imooc.com/65426563000100e202820238.jpg

   @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(); 

}

查看完整回答
反对 回复 2023-11-01
  • 1 回答
  • 0 关注
  • 104 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信