运行 按下 KeyEvent 时的 JButton
Run the JButton when a KeyEvent has been pressed
frame.addKeyListener(new java.awt.event.KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key typed = " + e.getKeyChar());
if(e.getKeyCode() == KeyEvent.VK_ENTER){
//My JButton is called b1, how do i make it run here when enter is pressed?
System.out.println("ENTER");
}
}
});
我修复了它我所要做的就是添加
b1.doClick();
在我的 if 语句中
frame.addKeyListener(new java.awt.event.KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key typed = " + e.getKeyChar());
if(e.getKeyCode() == KeyEvent.VK_ENTER){
//My JButton is called b1, how do i make it run here when enter is pressed?
System.out.println("ENTER");
}
}
});
我修复了它我所要做的就是添加
b1.doClick();
在我的 if 语句中