swing开发中,哪种最有效率和美观的事件处理
请教一下各路高手,在java中事件的处理一下三种哪种最好,还是有更好的?
import java.awt.*;import javax.swing.*;import java.awt.event.*;import javax.swing.event.*;public class Demo1 extends JFrame implements ActionListener { JButton btn = new JButton("方法 1"); JButton btn2 = new JButton("方法 2"); JButton btn3 = new JButton("方法 3"); Cat cat = new Cat(); public static void main(String[] args) { Demo1 d1 = new Demo1(); } public Demo1() { //方法1 this.btn.addActionListener(this); //方法2 this.btn2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showInputDialog("Btn2"); } } ); //方法3 this.btn3.addActionListener(this.cat); this.setLayout(new FlowLayout(FlowLayout.LEFT)); this.getContentPane().add(this.btn); this.getContentPane().add(this.btn2); this.getContentPane().add(this.btn3); this.setVisible(true); this.setSize(320,200); this.setLocation(500,300); this.setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e) { if(e.getSource() == btn) { JOptionPane.showConfirmDialog(this, "Btn"); } }} class Cat implements ActionListener{ public void actionPerformed(ActionEvent e) { JOptionPane.showInputDialog("Btn3"); }}