- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是javafx新手,当鼠标单击登录按钮时我正在使用操作属性,我希望在按下回车键时使用相同的代码,是否有更有效的方法除了复制相同的代码之外,还可以执行此操作。下面是我的 javafx 登录 Controller 中的代码:
@FXML
private void handleButtonAction(ActionEvent event) throws IOException {
System.out.println("Login button selected");
/*
* All Exceptions caught at the GUI not at the other two layers.
*/
try {
/*
* Reference 'bal' to Object BusinessAccessLogin sends parameters to Business Layer
* calling method login() which passes the TextBox parameters usernameBox and
* passwordBox down the layers.
*/
if (bal.login(usernameBox, passwordBox) && (count > 0)) {
/*
* Switch statement so that: user cat 1 -> Reception screen;
* user cat 2 'Nurses' -> triage screen ; & user cat 3 'Doctors -> treatment room
*/
switch(bal.staffAccess(usernameBox, passwordBox)){
case 1:
System.out.println("Staff Category ONE");
homePageParent = FXMLLoader.load(getClass().getResource("/views/FXMLReceptionistPage.fxml"));
homePageScene = new Scene(homePageParent);
appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
break;
case 2:
System.out.println("Staff Category TWO");
homePageParent = FXMLLoader.load(getClass().getResource("/views/FXMLTriageNurseHomePage.fxml"));
homePageScene = new Scene(homePageParent);
appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
break;
case 3:
System.out.println("Staff Category THREE");
homePageParent = FXMLLoader.load(getClass().getResource("/views/FXMLDoctorAssessmentPage.fxml"));
homePageScene = new Scene(homePageParent);
appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
break;
case 4:
System.out.println("Staff Category FOUR");
homePageParent = FXMLLoader.load(getClass().getResource("/views/FXMLHospitalManagerPage.fxml"));
homePageScene = new Scene(homePageParent);
appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
break;
}
appStage.setScene(homePageScene);
appStage.show();
appStage.centerOnScreen();
appStage.setMaximized(true);
} else {
usernameBox.clear();
passwordBox.clear();
--count;
invalidLabel.setText("Sorry, invalid details");
if (count < 1) {
invalidLabel.setText("You have been locked out of system");
appStage.close();
}
attemptLabel.setText("ATTEMPTS LEFT : " + count);
System.out.println("ATTEMPTS LEFT : " + count);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
} catch (Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
这是我希望在按下回车键时调用的代码。任何帮助将不胜感激
最佳答案
问题有点不清楚,但我猜测你想要的是方法 setDefaultButton .
A default Button is the button that receives a keyboard VK_ENTER press, if no other node in the scene consumes it.
关于java - 单击时的actionEvent,希望与输入键java fx相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29878414/
已经尝试解决这个问题一天多了,现在抛出白旗。在 UMUC 上这门课,这几乎是一个自学类(class),没有任何帮助,所以我真的很高兴能够在这里提出这个问题。 只是从概念上问这个问题,因为我什至无法理解
我有一个带有属性 pin、发件人姓名、收件人姓名、发件人电话、金额的现金表单,以及另一个带有属性 pin、发件人姓名、收件人姓名、发件人电话、金额、银行名称、帐号的表单帐户。 两种形式都有发送命令 现
我需要做的是一个生产者/消费者程序。我需要做 2 个生产者线程(第一个将继续发送 AcionEvent,间隔 4 秒,第二个将执行相同的操作,间隔 10 秒)。消费者线程需要是带有 JTextArea
我注意到,即使指定条件语句,ActionEvent 仍会在我的 JRadioButtonMenuItem 组中触发: if(!button.isSelected()) //Do stuff
简而言之: 我正在致力于使用 AI 和 GUI 创建纸牌游戏。用户的手显示在游戏界面上,我尚未完成界面,但我打算将牌面图像添加到屏幕上的矩形中。我没有找到 5 种几乎相同的方法,而是找到了一篇类似的文
我看过网上的java教程,它们似乎都关心捕获其他已编写的组件发出的ActionEvents。是否可以编写自己的对象,这些对象有自己的一组标准来触发actionEvents,然后可以被注册为监听器的其他
最近我一直在玩 Java Swing,并尝试创建一个自定义的 Minecraft 服务器启动器。当我按下标有“属性”的按钮时,它应该更改为一个新面板并在某一时刻执行此操作。但是,由于某种原因,我看不到
我已经扩展了 JTextField。我的类(class)有多个 ActionListeners,但我特别需要一个始终首先触发。有没有办法确保特定的 ActionEvent 总是最先出现? 请注意,我确
我正在制作一个程序,可以根据用户输入用文字或字符包装文本。我的所有工作正常,但ActionEvent却给我一个“找不到符号”错误。我敢肯定,我错过了一些小东西,但是我似乎找不到它: import ja
我构建了一个简单的 JavaFX 应用程序,当鼠标进入椭圆时,我不想在椭圆的中心创建一个圆。 这是一些代码: ellipse = new Ellipse(30,30,40,40); ellipse.s
为了测试我对 Java 接口(interface)的理解,我将按钮单击事件处理程序中的匿名类拉到一个单独的类中 - 这已经起作用了 - 但我不明白它为什么起作用。 我原以为必须自己调用类的 handl
我还是 Java 新手,在单击按钮时更改 JLabel 中的图像时遇到问题。我没有收到任何编译器错误,但确实收到了运行时错误。 Line 107: l1.setIcon(icon); “线程“AWT-
我已经在这方面得到了一些帮助,但是现在当我按下按钮时,没有任何反应。我希望当您单击按钮时显示文本。如果是布局问题,我应该使用哪一个? FlowLayout 不适用于此程序,因为它会扭曲按钮。 impo
我试图在按下按钮时启用/禁用标签,并且我想在事件期间而不是事件之后执行此操作。正如您在下面看到的,我尝试启用/禁用两个标签:lblKeyboard 和 lblGamepad。 它们最终在“Remote
我有两个类,一个包含两个组合框的 gui 类和一个监听两个组合框的监听器类。该软件是关于披萨的,组合框是选择披萨的类型和数量,我将发布相关代码。 (gui class) private Listene
找到解决方案 决定在 actionListener 之外创建一个名为 chairPrice 的方法更容易,该方法可以通过名为 getItemPrice() 的方法递增。这已用于计算元素和作品总价的10
我的代码属于 LWUIT 应用程序,但存在 LWUIT 和 java swing 之间常见问题。 我有一个表格,在它的最后一个单元格上设置了一个按钮作为组件 我的问题只是为什么当我按下该按钮时没有发生
我是 Java 新手,正在开发一个看起来像标准介绍项目的项目,该项目创建多个 (<10) 个计时器,每个计时器都可以独立启动和停止。启动后,它们会每秒从初始启动时间开始倒计时一次,并显示更新等等。 我
我正在开发一个相当大(且有缺陷)的 JSF 应用程序,用户经常提示我们难以重现的问题。 是否可以拦截所有 ActionEvents 的创建,以便我可以记录它们的创建? 如果没有,是否有一种自动方式(J
首先,如果标题很简短,我深表歉意,我已经考虑过,但无法为我的问题提供足够短的摘要。 我有一个由 JButton 组成的 JPanel 类。 我有我的主 Swing 应用程序类,其中包含 Swing 组
我是一名优秀的程序员,十分优秀!