publicclassQuickKey{publicstaticvoidmain(String[]args){JFrameframe=newJFrame();frame.setBounds(100,200,400,400);frame.setLayout(null);JButtonbutton=newJButton("复制上一个...
public class QuickKey{public static void main(String[] args) {JFrame frame = new JFrame();frame.setBounds(100,200,400,400);frame.setLayout(null);JButton button = new JButton("复制上一个(F9)");button.setBounds(50,50,120,30);button.setFont(new Font("幼圆",Font.PLAIN, 10));button.registerKeyboardAction(new ActionRefresh(), KeyStroke.getKeyStroke("F9"), JComponent.WHEN_IN_FOCUSED_WINDOW);frame.add(button);frame.setVisible(true);}}public class ActionRefresh implements ActionListener {private Robot robot;@Overridepublic void actionPerformed(ActionEvent e) {try { robot = new Robot();} catch (AWTException e1) {}robot.keyPress(KeyEvent.VK_UP);robot.keyRelease(KeyEvent.VK_UP); ... /* 这段代码是我知道瞎写的,意思就是先按向上方向键复制,再 按下方向键粘*/ }}
展开