import java.awt.*;//问题程序,出错在哪?这是教材上的一个例题程序,我把它改成现在这个样了,但我找不出它的毛病在哪儿!
import java.awt.event.*;
class WindowTen extends Frame
{Panel p;
Button a;
ScrollPane scrollpane;
WindowTen()
{p=new Panel();
setLayout(new FlowLayout());
scrollpane=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
a=new Button("close");
a.addActionListener(this);
add(a);
p.add(new Button("two"));
p.add(new Button("one"));
scrollpane.add(p);
add(scrollpane);
setBounds(60,60,500,500);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{ System.exit(0);}
}
public class win
{ public static void main(String args[])
{WindowTen s=new WindowTen();}
}

解决方案 »

  1.   

    a.addActionListener(this); 错了,参数应为Listenerpublic class win  把public去掉
      

  2.   

    让WindowTen实现ActionListener接口
      

  3.   

    public void actionPerformed(ActionEvent e)
    { System.exit(0);}
    }
    这段代码删了,a.addActionListener(this);改成:
    a.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) {
    System.exit(0);
    }

    });
      

  4.   

    import java.awt.*;//问题程序,出错在哪?这是教材上的一个例题程序,我把它改成现在这个样了,但我找不出它的毛病在哪儿!
    import java.awt.event.*;
    class WindowTen extends Frame implements ActionListener
    {Panel p;
    Button a;
    ScrollPane scrollpane;
    WindowTen()
    {p=new Panel();
    setLayout(new FlowLayout());
    scrollpane=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
    a=new Button("close");
    a.addActionListener(this);
    add(a);
    p.add(new Button("two"));
    p.add(new Button("one"));
    scrollpane.add(p);
    add(scrollpane);
    setBounds(60,60,500,500);
    setVisible(true);
    validate();
    }
    public void actionPerformed(ActionEvent e)
    { System.exit(0);}
    }
    public class Win
    { public static void main(String args[])
    {WindowTen s=new WindowTen();}
    }
      

  5.   

    他原来实现了ActionListener接口,所以可以a.addActionListener(this);
    你为什么要把implements ActionListener去掉
      

  6.   

    晕,我忘记了+ActionListener