AWT和Swing是java中常见的GUI(图形界面)技术
AWT是java中最老的GUI技术 但实际开发很少用到 JavaEE做设计全都是网页
package cn.sxt.game; import javax.swing.JFrame; /** * 飞机游戏的主窗口 * @author Vitol * */ public class MyGameFrame extends JFrame { /** * 初始化窗口 */ public void launchFrame() { this.setTitle("尚学堂学员_Vitol作品"); //标题 this.setVisible(true); //设置窗口是否可见 } public static void main(String[] args) { MyGameFrame mgf = new MyGameFrame(); mgf.launchFrame(); } }
效果图如下:
2.
1 package cn.sxt.game; 2 3 import java.awt.event.WindowAdapter; 4 import java.awt.event.WindowEvent; 5 6 import javax.swing.JFrame; 7 8 import javax.swing.JFrame; 9 10 /** 11 * 飞机游戏的主窗口 12 * @author Vitol 13 * 14 */ 15 public class MyGameFrame extends JFrame { 16 17 /** 18 * 初始化窗口 19 */ 20 public void launchFrame() { 21 22 this.setTitle("尚学堂学员_Vitol作品"); //标题 23 this.setVisible(true); //设置窗口是否可见 24 this.setSize(500,500); //设置窗口大小 25 this.setLocation(300,300); //设置窗口位置 26 27 //点差结束程序 28 this.addWindowListener(new WindowAdapter() { 29 @Override 30 public void windowClosing(WindowEvent e) { 31 System.exit(0); 32 } 33 }); 34 35 } 36 37 public static void main(String[] args) { 38 //实例化对象 39 MyGameFrame f = new MyGameFrame(); 40 f.launchFrame(); 41 } 42 43 }
效果图: