public class MyGameFrame extends JFrame {public void paint(Graphics g) {g.drawLine(100,100,300,300);}/* * 初始化窗口 */public void launchFrame() {this.setTitle("打飛機小游戲");this.setVisible(true);//設置為可見this.setSize(500,500);//設置窗口的長度、寬度this.setLocation(300,300);//設置窗口的位置/** 設置關閉窗口功能*/this.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e) {System.exit(0);}});}public static void main(String[] args){MyGameFrame f = new MyGameFrame();f.launchFrame();f.setVisible(true);}}
4 回答

那你那
TA貢獻1條經驗 獲得超4個贊
直接把 this.Visible(true);
放到
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
的后邊就解決了
添加回答
舉報
0/150
提交
取消