首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-09-09 
JButton 加事件监听(鼠标和键盘)ActionListener okListenernew ActionListener(){public void actionPerf

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);
?

热点排行