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

📄 mainframe.java

📁 Java 小游戏TetraSquare
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * mainFrame.java
 *
 * Created on 2007年3月12日, 下午8:09
 */

package tetrasquare;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 *
 * @author  Caviar
 */
public class mainFrame extends javax.swing.JFrame {
    
    /** Creates new form mainFrame */
    public mainFrame() {
        
        initComponents();               
        initGrid();        
        initShortcut();
        initMusicListener();  
        initUserListener();
        initInterfaceListener();
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        buttonGroup1 = new javax.swing.ButtonGroup();
        music = new javax.swing.ButtonGroup();
        faceGroup = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        gamefield = new javax.swing.JPanel();
        statistics = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        nextshape = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        GameMenu = new javax.swing.JMenu();
        NewGame = new javax.swing.JMenuItem();
        changecolor = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        login = new javax.swing.JMenu();
        user1 = new javax.swing.JRadioButtonMenuItem();
        user2 = new javax.swing.JRadioButtonMenuItem();
        user3 = new javax.swing.JRadioButtonMenuItem();
        user4 = new javax.swing.JRadioButtonMenuItem();
        user5 = new javax.swing.JRadioButtonMenuItem();
        user6 = new javax.swing.JRadioButtonMenuItem();
        user7 = new javax.swing.JRadioButtonMenuItem();
        user8 = new javax.swing.JRadioButtonMenuItem();
        ViewHighScore = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        open = new javax.swing.JMenuItem();
        save = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        exit = new javax.swing.JMenuItem();
        Help = new javax.swing.JMenu();
        howtoplay = new javax.swing.JMenuItem();
        about = new javax.swing.JMenuItem();
        Music = new javax.swing.JMenu();
        nomusic = new javax.swing.JRadioButtonMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        music1 = new javax.swing.JRadioButtonMenuItem();
        music2 = new javax.swing.JRadioButtonMenuItem();
        music3 = new javax.swing.JRadioButtonMenuItem();
        music4 = new javax.swing.JRadioButtonMenuItem();
        Face = new javax.swing.JMenu();
        metal = new javax.swing.JRadioButtonMenuItem();
        winclassic = new javax.swing.JRadioButtonMenuItem();
        liquid = new javax.swing.JRadioButtonMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("TetreSquare");
        setBounds(new java.awt.Rectangle(400, 200, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(102, 153, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        gamefield.setLayout(new java.awt.GridLayout(8, 8));

        gamefield.setBackground(new java.awt.Color(255, 255, 255));
        gamefield.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        gamefield.setToolTipText("");

        statistics.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        statistics.setBackground(new java.awt.Color(255, 255, 255));
        statistics.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        statistics.setMaximumSize(new java.awt.Dimension(160, 160));
        statistics.setMinimumSize(new java.awt.Dimension(160, 160));
        jLabel1.setText("Level");
        statistics.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 40, -1));

        jLabel2.setText("Score");
        statistics.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 50, -1));

        jLabel3.setText("Pieces Left");
        statistics.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, 80, -1));

        statistics.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 20, 40, 15));

        statistics.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 70, 40, 15));

        statistics.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 120, 40, 15));

        nextshape.setLayout(new java.awt.GridLayout(5, 5));

        nextshape.setBackground(new java.awt.Color(255, 255, 255));
        nextshape.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(gamefield, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(statistics, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(nextshape, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(gamefield, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(statistics, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                        .addComponent(nextshape, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        GameMenu.setText("\u6e38\u620f(G)");
        NewGame.setText("\u5f00\u59cb\u65b0\u6e38\u620f(N)");
        NewGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NewGameActionPerformed(evt);
            }
        });

        GameMenu.add(NewGame);

        changecolor.setText("\u66f4\u6362\u989c\u8272\u65b9\u6848");
        changecolor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changecolorActionPerformed(evt);
            }
        });

        GameMenu.add(changecolor);

        GameMenu.add(jSeparator1);

        login.setText("\u767b\u5f55\u7528\u6237(L)");
        buttonGroup1.add(user1);
        user1.setText("\u7528\u62371");
        login.add(user1);

        buttonGroup1.add(user2);
        user2.setText("\u7528\u62372");
        login.add(user2);

        buttonGroup1.add(user3);
        user3.setText("\u7528\u62373");
        login.add(user3);

        buttonGroup1.add(user4);
        user4.setText("\u7528\u62374");
        login.add(user4);

        buttonGroup1.add(user5);
        user5.setText("\u7528\u62375");
        login.add(user5);

        buttonGroup1.add(user6);
        user6.setText("\u7528\u62376");
        login.add(user6);

        buttonGroup1.add(user7);
        user7.setText("\u7528\u62377");
        login.add(user7);

        buttonGroup1.add(user8);
        user8.setText("\u7528\u62378");
        login.add(user8);

        GameMenu.add(login);

        ViewHighScore.setText("\u9ad8\u5206\u6392\u884c\u699c(F)");
        ViewHighScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ViewHighScoreActionPerformed(evt);
            }
        });

        GameMenu.add(ViewHighScore);

        GameMenu.add(jSeparator2);

        open.setText("\u7ee7\u7eed\u6e38\u620f(O)");
        open.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openActionPerformed(evt);
            }
        });

        GameMenu.add(open);

        save.setText("\u4fdd\u5b58\u6e38\u620f(S)");
        save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveActionPerformed(evt);
            }
        });

        GameMenu.add(save);

        GameMenu.add(jSeparator3);

        exit.setText("\u9000\u51fa(X)");
        exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitActionPerformed(evt);
            }
        });

        GameMenu.add(exit);

        jMenuBar1.add(GameMenu);

        Help.setText("\u5e2e\u52a9(E)");
        howtoplay.setText("\u5982\u4f55\u6e38\u620f(H)");
        howtoplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                howtoplayActionPerformed(evt);
            }
        });

        Help.add(howtoplay);

        about.setText("\u5173\u4e8e(A)");
        about.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutActionPerformed(evt);
            }
        });

        Help.add(about);

        jMenuBar1.add(Help);

        Music.setText("\u97f3\u4e50(M)");
        music.add(nomusic);
        nomusic.setText("\u4e0d\u8981\u97f3\u4e50");
        Music.add(nomusic);

        Music.add(jSeparator4);

        music.add(music1);
        music1.setText("01 - Recalled days");
        Music.add(music1);

        music.add(music2);
        music2.setText("02 - Canon");
        Music.add(music2);

        music.add(music3);
        music3.setText("03 - SUNSET");
        Music.add(music3);

        music.add(music4);
        music4.setText("04 - Swing Town");
        Music.add(music4);

        jMenuBar1.add(Music);

        Face.setText("\u66f4\u6362\u76ae\u80a4(F)");
        faceGroup.add(metal);
        metal.setText("Metal Styled");
        Face.add(metal);

        faceGroup.add(winclassic);
        winclassic.setText("Windows Classic");
        Face.add(winclassic);

        faceGroup.add(liquid);
        liquid.setSelected(true);
        liquid.setText("Liquid");
        Face.add(liquid);

        jMenuBar1.add(Face);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

⌨️ 快捷键说明

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