我想做一个窗体,关可以关闭这么简单,我的代码是:
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends Frame implements WindowListener{
public static void main(String ags[])
{
MyFrame fr=new MyFrame("聊天对话框");
fr.setSize(400,400);
fr.setVisible(true);
fr.addWindowListener(this);
}
public MyFrame(String str)
{
super(str);
}
public void windowClosing(WindowEvent e){System.exit(1);}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
}
我编译不了,我的代码有什么问题呀,应怎么改才是正确的呀,为什么????
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends Frame implements WindowListener{
public static void main(String ags[])
{
MyFrame fr=new MyFrame("聊天对话框");
fr.setSize(400,400);
fr.setVisible(true);
fr.addWindowListener(this);
}
public MyFrame(String str)
{
super(str);
}
public void windowClosing(WindowEvent e){System.exit(1);}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
}
我编译不了,我的代码有什么问题呀,应怎么改才是正确的呀,为什么????
{
MyFrame fr=new MyFrame("聊天对话框");
fr.setSize(400,400);
fr.setVisible(true);
fr.addWindowListener(this);/////////////////////////////////////
}
错了,静态方法里面不能用this.
{
MyFrame fr=new MyFrame("聊天对话框");
fr.setSize(400,400);
fr.setVisible(true);
fr.addWindowListener(fr);//this --> fr
}