Java 中是否有一种方法可以执行按下操作按钮?,我需要这个,因为我想制作一个 KeyListener,当您按下键盘上的按钮时,“5”会在 gui 描述“5”中启动我按钮;
编辑
我得到了 ActionListener:
public void actionPerformed(ActionEvent event){
if(button.getLabel().equals("1")){
// do something
}
}
和 KeyListener
public void keyPressed(KeyEvent e){
if (e.getKeyCode() == VK_NUMPAD1) {
// do what would happen if I pressed the mouse on the button
// I do not know how to execute it thought that it was pressing down the
// button with the label '1 '
}
}