62,635
社区成员




import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Test {
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setSize(400, 300);
JButton button = new JButton("按钮");
InputMap inputMap = button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = button.getActionMap();
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), "home");
actionMap.put("home", new AbstractAction(){
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(frame, "你按下了HOME键");
}
});
frame.add(new JButton("按钮"), BorderLayout.NORTH);
frame.add(button, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}