原文地址:http://blog.163.com/love_ccxx/blog/static/1806322122011102215425405/
1. JFrame是javax.swing.JFrame的类,Frame是java.awt.Frame的类
2. 关闭窗口的方式不同:
2.1 JFrame的关闭方式:
import javax.swing.JFrame;
public class JFrameTest extends JFrame{ /** * */ private static final long serialVersionUID = 1L; @SuppressWarnings("static-access") public void init(){ //传递参数使得关闭按钮有效 this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); this.setTitle("JFrame"); this.setSize(320,240); this.setVisible(true); } public static void main(String[] args){ JFrameTest jframe = new JFrameTest(); jframe.init(); } }
2.2 Frame的关闭方式:
未完·······待续~
import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;
public class FrameTest extends Frame{ /** * */ private static final long serialVersionUID = -5650765517644858632L;
public void init(){ this.setSize(320,240); this.setTitle("Frame"); //加监听使得关闭按钮有效 this.addWindowListener(new WindowAdapter(){ @Override public void windowClosing(WindowEvent e){ System.exit(0); } }); this.setVisible(true); } public static void main(String[] args){ FrameTest frame = new FrameTest(); frame.init(); } }