小弟编写的程序为:
public JFrame Conformation()
{
panel = new JPanel();
button1 = new JButton();
button2 = new JButton();
ConformationListener listener = new ConformationListener();

button1.addActionListener(listener);
button2.addActionListener(listener);

panel.add(button1);
panel.add(button2);
}//===================================================================================例题程序给的:
   public Simple1() { 
        // 新建面板 
        myPanel = new JPanel(); 
        // 新建按钮 
        button1 = new JButton("按钮1");  // 新建按钮1 
        button2 = new JButton("按钮2");         SimpleListener ourListener = new SimpleListener(); 
        // 建立一个actionlistener让两个按钮共享 
        button1.addActionListener(ourListener); 
        button2.addActionListener(ourListener);         myPanel.add(button1); // 添加按钮到面板 
        myPanel.add(button2); 
    } //============================================================这个就是简单的在两个按钮上加上监听器,但是为什么例题程序中没有返回值也可以运行,儿我的程序没有返回值就不能运行?
弹出错误为:
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1027)
at java.awt.Container.add(Container.java:352)
at Chapter3.ActionListenerPractice.main(ActionListenerPractice.java:53)//============================================================我觉得mian写的都一样啊,希望达人指教~~~