产生并显示一个窗口
操作步骤:
1.新建一个类MyWin,继承java.awt.Frame类
2.在MyWin类中写一个方法launchFrame
3.在launchFrame方法中设置窗口位置:setLocation
4.在launchFrame方法中设置窗口大小:setSize
5.在launchFrame方法中设置窗口标题栏:setTitle
6.在launchFrame方法中设置窗口为可见:setVisible
7.在launchFrame方法中为窗口类添加窗口监听:addWindowListener
8.在launchFrame方法中设置不允许改变窗口大小:setResizable
9.最后在main方法中new一个MyWin对象,然后调用其launchFrame方法
例如:
import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @SuppressWarnings("serial") public class MyWin extends Frame { public void launchFrame() { this.setLocation(0, 0); this.setSize(800, 600); this.setTitle("TankWar"); this.setVisible(true); this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } }); this.setResizable(false); } public static void main(String[] args) { MyWin win = new MyWin(); win.launchFrame(); } }