两个控件的单击事件是一致的:
JButton单击事件:
JButton but=new JButton("按钮"); but.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.out.println("==================="); } });
JComboBox事件:
JComboBox box= new JComboBox(); box.addItem("test1"); box.addItem("test2"); box.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.out.println("---------------------"); } });