读书人

JButton 添事件监听(鼠标和键盘)

发布时间: 2012-09-09 09:27:54 作者: rapoo

JButton 加事件监听(鼠标和键盘)

ActionListener okListener=new ActionListener(){public void actionPerformed(ActionEvent evt) {//storing the filechooser's current directoryEditor.getEditor().getResourcesManager().setCurrentDirectory(fileChooser.getCurrentDirectory());setVisible(false);}};okButton=new JButton(okLabel);//the ok action nameString actionName="okAction";//registering the ok actionAction okAction=new AbstractAction(actionName){public void actionPerformed(ActionEvent e) {okButtonListener.actionPerformed(e);}};okButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), actionName);okButton.getActionMap().put(actionName, okAction);okButton.addActionListener(okButtonListener);
?

读书人网 >编程

热点推荐