添加事件监听器,覆盖actionFormed方法。比如说:b.addActionListener(new ActionListener){ public void actionPerformed(ActionEvent e) { .............. }});使用了匿名内部类。