调了一个下午还不对....闷.....
import java.awt.*;import java.awt.event.*;public class Cen{ private static Button b; private static Button c; public static void main(String args[]) { Frame f=new Frame("Test"); b=new Button("B"); b.addActionListener(new ButtonHandler()); //好象这里报错..... c=new Button("C"); c.addActionListener(new ButtonHandler()); f.setLayout(new FlowLayout()); f.add(b); f.add(c); f.setSize(200,100); f.setVisible(true); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println("all"); //这个地方输出有问题 if(e.getSource().equals(b)) System.out.println("b"); if(e.getSource().equals(c)) System.out.println("c"); } }}import java.awt.Button;import java.awt.FlowLayout;import java.awt.Frame;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;@SuppressWarnings("serial")public class MyFrame extends Frame { private Button b; private Button c; public MyFrame() { super("Test"); ButtonHandler bh = new ButtonHandler(); this.b = new Button("B"); this.b.addActionListener(bh); this.c = new Button("C"); this.c.addActionListener(bh); setLayout(new FlowLayout()); add(this.b); add(this.c); setSize(200, 100); pack(); } private class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println("all"); if (e.getSource() == b) System.out.println("b"); if (e.getSource() == c) System.out.println("c"); } } public static void main(String[] args) { MyFrame mf = new MyFrame(); mf.setVisible(true); }}