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

📄 tetricsframe.java

📁 使用java编的俄罗斯方块
💻 JAVA
字号:
package tetrics;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TetricsFrame
    extends JFrame {
  JPanel contentPane;
  BorderLayout borderLayout1 = new BorderLayout();
  JMenuBar jMenuBar1 = new JMenuBar();
  JMenu jMenu1 = new JMenu();
  JMenuItem start = new JMenuItem();
  JMenuItem pause = new JMenuItem();
  JMenuItem end = new JMenuItem();
  JMenuItem quit = new JMenuItem();
  JMenu jMenu2 = new JMenu();
  JMenuItem level = new JMenuItem();
  JMenu jMenu3 = new JMenu();
  JMenuItem about = new JMenuItem();

  Tetrics m_tetrics = new Tetrics();

  //Construct the frame
  private int nScore;
  JPanel jPanel1 = new JPanel();
  JLabel jLabel1 = new JLabel();
  JMenuItem score = new JMenuItem();
  public TetricsFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
      this.setJMenuBar(jMenuBar1);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit() throws Exception {
    contentPane = (JPanel)this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(450, 500));
    this.setJMenuBar(jMenuBar1);
    this.setTitle("Tetrics");
    jMenu1.setText("游 戏");
    start.setText("开始游戏");
    start.addActionListener(new TetricsFrame_start_actionAdapter(this));
    pause.setText("暂停游戏");
    pause.addActionListener(new TetricsFrame_pause_actionAdapter(this));
    end.setText("结束游戏");
    end.addActionListener(new TetricsFrame_end_actionAdapter(this));
    quit.setText("关 闭");
    quit.addActionListener(new TetricsFrame_quit_actionAdapter(this));
    jMenu2.setText("控 制");
    level.setText("设置级别");
    level.addActionListener(new TetricsFrame_level_actionAdapter(this));
    jMenu3.setText(" 关 于");
    about.setText("关 于");
    about.addActionListener(new TetricsFrame_about_actionAdapter(this));
    contentPane.setBackground(new Color(80, 123, 166));

    jLabel1.setText("游戏装载完毕");
    jPanel1.setBorder(BorderFactory.createLineBorder(Color.black));
    score.setText("查看分数");
    score.addActionListener(new TetricsFrame_score_actionAdapter(this));
    jMenuBar1.add(jMenu1);
    jMenuBar1.add(jMenu2);
    jMenuBar1.add(jMenu3);
    jMenu1.add(start);
    jMenu1.add(pause);
    jMenu1.add(end);
    jMenu1.addSeparator();
    jMenu1.add(quit);
    jMenu2.add(level);
    jMenu2.add(score);
    jMenu3.add(about);

    contentPane.add(m_tetrics, BorderLayout.CENTER);
    contentPane.add(jPanel1, BorderLayout.SOUTH);
    jPanel1.add(jLabel1, null);

  }

  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

  void start_actionPerformed(ActionEvent e) {
    m_tetrics.start();
    jLabel1.setText("开始游戏");
    this.repaint();
  }

  void pause_actionPerformed(ActionEvent e) {
    //控制暂停游戏的代码加到这儿。
    m_tetrics.pause();
    jLabel1.setText("暂停游戏");
    this.repaint();

  }

  void end_actionPerformed(ActionEvent e) {
    //控制结束游戏的代码加到这儿。
    m_tetrics.stop();
    jLabel1.setText("结束游戏");
    this.repaint();
  }

  void quit_actionPerformed(ActionEvent e) {
    this.dispose();
    //
  }

  public void insertScoreReport(int m_nTheScore) {
    Score score = new Score();
    if (score.isScoreTop(nScore)) {
      Dialog d = new Dialog(this, "恭喜");
      InsertPanel ius=new InsertPanel(nScore,d);
      d.add(ius);
      d.setSize(306, 231);
      d.setLocation(400, 300);
      d.show();
    }
  }


  void about_actionPerformed(ActionEvent e) {
    AboutDialog ad = new AboutDialog(this);
    this.repaint();
  }

  void level_actionPerformed(ActionEvent e) {
    Dialog d = new Dialog(this, "设置级别");
    LevelDialog ld = new LevelDialog(this, d);
    d.add(ld);
    d.setSize(300, 150);
    d.setLocation(400, 300);
    d.setLocation(300,200);
    this.repaint();
    d.show();

  }

  void score_actionPerformed(ActionEvent e) {
    //控制设置级别的代码加到这儿。
       Dialog d=new Dialog(this,"分数报告-Top10");
       ReportPanel srp=new ReportPanel(d);
       d.add(srp);
       d.setSize(643,300);
       d.setLocation(400,300);
       d.show();
  }


}

class TetricsFrame_start_actionAdapter
    implements java.awt.event.ActionListener {
  TetricsFrame adaptee;

  TetricsFrame_start_actionAdapter(TetricsFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.start_actionPerformed(e);
  }
}

class TetricsFrame_pause_actionAdapter
    implements java.awt.event.ActionListener {
  TetricsFrame adaptee;

  TetricsFrame_pause_actionAdapter(TetricsFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.pause_actionPerformed(e);
  }
}

class TetricsFrame_end_actionAdapter
    implements java.awt.event.ActionListener {
  TetricsFrame adaptee;

  TetricsFrame_end_actionAdapter(TetricsFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.end_actionPerformed(e);
  }
}

class TetricsFrame_quit_actionAdapter
    implements java.awt.event.ActionListener {
  TetricsFrame adaptee;

  TetricsFrame_quit_actionAdapter(TetricsFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.quit_actionPerformed(e);
  }
}

class TetricsFrame_about_actionAdapter
    implements java.awt.event.ActionListener {
  TetricsFrame adaptee;

  TetricsFrame_about_actionAdapter(TetricsFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.about_actionPerformed(e);
  }
}

class TetricsFrame_level_actionAdapter
    implements java.awt.event.ActionListener {
  TetricsFrame adaptee;

  TetricsFrame_level_actionAdapter(TetricsFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.level_actionPerformed(e);
  }
}

class TetricsFrame_score_actionAdapter implements java.awt.event.ActionListener {
  TetricsFrame adaptee;

  TetricsFrame_score_actionAdapter(TetricsFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.score_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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