import javax.swing.*;public class Text2
{ public static void main(String[] args)
{
JFrame f=new JFrame();
f.setSize(333, 333);
f.setVisible(true);
System.out.print(11111);
}
}这个程序怎么让f关闭?????谁帮我添下代码
{ public static void main(String[] args)
{
JFrame f=new JFrame();
f.setSize(333, 333);
f.setVisible(true);
System.out.print(11111);
}
}这个程序怎么让f关闭?????谁帮我添下代码
System.exit(0);
}
});
f.dispose();会释放资源,好像问了四五个人,只有一个人经常这样做,
import javax.swing.*;
public class Text2 {
public static void main(String[] args) {
final JFrame f = new JFrame();
f.setSize(333, 333);
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.setVisible(false);
f.dispose();
System.exit(0);
}
});
}
}
应该用windowClosing().
并且f.setVisible(false);
f.dispose();
System.exit(0);
这样写感觉好一点!