⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sbmain.java

📁 java编写的打鸟游戏
💻 JAVA
字号:
/* * SBMain.java * * Created on 2007年12月18日, 下午12:22 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package SBGameCore;import graphics.ScorePanel;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JSeparator;/** * * @author wusir */public class SBMain extends JFrame implements ActionListener{    GraphicsPanel gp=new GraphicsPanel();    ScorePanel sp = new ScorePanel();    JMenuBar menuBar = new JMenuBar();    JMenu game_Menu = new JMenu();    JMenuItem newGame_Item = new JMenuItem();    JSeparator jSeparator = new JSeparator();    JMenuItem Exit_Item = new JMenuItem();    BorderLayout layout=new BorderLayout();    int score = 0;    String name = null;    Score scorec = null;    /** Creates a new instance of SBMain */    public SBMain() {        scorec =new Score();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        setTitle("ShotBird");        game_Menu.setText("\u6e38\u620f");        newGame_Item.setText("\u65b0\u5efa\u6e38\u620f");        newGame_Item.addActionListener(this);        game_Menu.add(newGame_Item);                game_Menu.add(jSeparator);                Exit_Item.setText("\u505c\u6b62");        Exit_Item.addActionListener(this);                game_Menu.add(Exit_Item);        Exit_Item.setEnabled(false);        menuBar.add(game_Menu);                setJMenuBar(menuBar);                setPreferredSize(new Dimension(1000,700));                setLayout(layout);        //add(game_Menu,layout.NORTH);        add( sp,layout.CENTER);        pack();        setResizable(false);    }        public void actionPerformed(ActionEvent e) {        if (e.getSource() == Exit_Item) {            this.Exit_ItemActionPerformed(e);        } else if (e.getSource() == newGame_Item) {            this.newGame_ItemActionPerformed(e);        }    }    private void Exit_ItemActionPerformed(java.awt.event.ActionEvent evt) {        Exit_Item.setEnabled(false);        newGame_Item.setEnabled(true);        score = gp.score;        scorec.addRecord(name,score);        this.gp.bgSound.stop();        this.gp.game.stop() ;        this.remove(gp);        //sp.;        this.add(sp,layout.CENTER);        sp.repaint();        // System.exit(0);    }    private void newGame_ItemActionPerformed(java.awt.event.ActionEvent evt) {        this.remove(sp);                //gp.init();        gp.score = 0;        gp.Nbullet = 3;        gp.resetBirdsSpeed();        gp.speedupId = 5;        this.add(gp,layout.CENTER);        name=JOptionPane.showInputDialog("Your Name")    ;        while (name.equals("")||name==null)            name=JOptionPane.showInputDialog("Your Name");        Exit_Item.setEnabled(true);        newGame_Item.setEnabled(false);        this.gp.Start() ;        this.gp.game  = new Thread(this.gp) ;        this.gp.game.setPriority(Thread.MIN_PRIORITY) ;        //线程启动        this.gp.game.start() ;        this.gp.buf_g.dispose() ;    }        /**     * @param args the command line arguments     */    public static void main(String[] args) {        // TODO code application logic here        SBMain sbm=new SBMain();        sbm.setVisible(true);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -