有两段代码,import就省掉了。
public class Char extends Frame { public static void main(String[] args) {
new Char().Struct();
} public void Struct() { setBounds(200, 200, 300, 300);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent w) {
setVisible(false);
System.exit(-1);
}
});
}}
第二段
public class ChatClient {
public static void main(String[] args){
Window c = new Window();
c.Struct();
}
}
 
class Window extends Frame{
void Struct(){
setBounds(400,400,300,300);
setVisible(true);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e){
setVisible(false);
System.exit(0);
}});
}
}
这个addWindowListener方法就会报错,为什么,不是一样用到方法吗,为什么第二种写法就不行了,还望高手赐教,究竟哪里错了?