publicTankGame(){//實例化構造菜單jmb=newJMenuBar();jm=newJMenu("游戲(G)");Jmc=newJMenu("關于");//設置快捷方式jm.setMnemonic('G');jm_start=newJMenuItem("開始新游戲(N)");jm_restart=newJMenuItem("重新開始游戲");jm_exit=newJMenuItem("退出()");jm.add(jm_start);jm.add(jm_restart);jm.add(jm_exit);jm_about=newJMenuItem("關于我們");Jmc.add(jm_about);jmb.add(jm);jmb.add(Jmc);this.setJMenuBar(jmb);msp=newMyStartPanel();this.setSize(Screen.screen_width,Screen.screen_higth);//設大一點,下面有用途this.add(msp);//作為剛運行時界面Thread st=newThread(msp);st.start();//監聽開始按鈕jm_start.addActionListener(this);jm_start.setActionCommand("newgame");//監聽關閉按鈕jm_exit.addActionListener(this);jm_exit.setActionCommand("exit");//監聽重新開始方法jm_restart.addActionListener(this);jm_restart.setActionCommand("restart");//監聽方法jm_about.addActionListener(this);jm_about.setActionCommand("aboutme");this.setVisible(true);}@OverridepublicvoidactionPerformed(ActionEvent e){// TODO Auto-generated method stub//創建戰場面板if(e.getActionCommand().equals("newgame")){//創建戰場面板mp=newMyPanel();Thread t =newThread(mp);t.start();//先刪除舊的開始面板this.remove(msp);this.addKeyListener(mp);//注冊監聽this.add(mp);startMusic();//顯示,刷新this.setVisible(true);}if(e.getActionCommand().equals("exit")){System.exit(0);}//重新開始游戲if(e.getActionCommand().equals("restart")){//游戲設置初始化Recorder.setEnNum(20);Recorder.setAllEnNum(0);Recorder.setMyLife(3);Recorder.setIsgameover(false);Recorder.setVictory(false);Recorder.setIsgameovermusic(false);this.remove(mp);//創建戰場面板mp=newMyPanel();Thread t =newThread(mp);t.start();this.addKeyListener(mp);//注冊監聽this.add(mp);startMusic();//顯示,刷新this.setVisible(true);}}