【发布时间】:2014-04-18 11:11:28
【问题描述】:
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 '
}
}
【问题讨论】:
-
不清楚你在问什么。你试过什么?
-
是的,它被称为 KeyListener。问题可能是您将此侦听器绑定到的组件(当它处于活动状态时)或您用于键盘的键码。显示一些代码。
标签: java button keylistener keypad