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();}
}
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();}
}
{ System.exit(0);}
}
这段代码删了,a.addActionListener(this);改成:
a.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
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();}
}
你为什么要把implements ActionListener去掉