我正在构建一个客户端/服务器应用程序。
我想让用户在身份验证框架上变得轻松。
I want to know how to make enter-key submits the login and password to the Database (Fires the Action) ?
一种方便的方法依赖于setDefaultButton() http://download.oracle.com/javase/7/docs/api/javax/swing/JRootPane.html#setDefaultButton%28javax.swing.JButton%29,如图所示example https://stackoverflow.com/questions/7456227/how-to-handle-events-from-keyboard-and-mouse-in-full-screen-exclusive-mode-in-jav/7457102#7457102并在中提到如何使用按键绑定 http://download.oracle.com/javase/tutorial/uiswing/misc/keybinding.html.
JFrame f = new JFrame("Example");
Action accept = new AbstractAction("Accept") {
@Override
public void actionPerformed(ActionEvent e) {
// handle accept
}
};
private JButton b = new JButton(accept);
...
f.getRootPane().setDefaultButton(b);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)