扫雷代码之界面(1)

1.扫雷的游戏界面
package com.saolei.view;


import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.*;

import com.saolei.model.ComputeModel;
import com.saolei.contorl.BoomLook;
import com.saolei.contorl.RightMouse;
import com.saolei.contorl.finalBoom;
public class BoomFrame extends JFrame{
 private JButton[][] but;
 private JButton start;
 private JPanel butpane,typepane;
    private JTextField num1;
    private JTextField num2;
    private int boomnum;
    private int bwidth;
    private int bhight;
    private int[] boompost;
    private long time,htime,s;
   
    public BoomFrame(int level){//游戏界面
     super("扫雷");
     time = System.currentTimeMillis();
     htime = System.currentTimeMillis();
  s = (htime - time)/1000;
  
     if (level == finalBoom.level0hight) {
      boomnum = finalBoom.level0boom;
  } else if(level == finalBoom.level1hight){
   boomnum = finalBoom.level1boom;
  }else if(level == finalBoom.level2hight){
   boomnum = finalBoom.level2boom;
  }
     bwidth = level;
     bhight = level;
     
     //给定雷的位置
     boompost=ComputeModel.getRandomBoom(bwidth, bhight, boomnum);
     
     int[] size = ComputeModel.getwindowsize(bwidth, bhight);
     this.setBounds(200-level*2,200-level*2,size[0],size[1]);
     this.setLayout(null);
     
     typepane = new JPanel(new FlowLayout(FlowLayout.CENTER,20,5));
     typepane.setBounds(5, 5, size[0]-8-10-10, 20*2+5);
     this.add(typepane);
     typepane.setBorder(finalBoom.Bor1);
     
     num1 = new JTextField("0"+boomnum+"" );
     typepane.add(num1);
     start = new JButton(finalBoom.start0);
     start.setBorder(finalBoom.Bor0);
     typepane.add(start);
     num2 = new JTextField("000");
     typepane.add(num2);
     
     
     // 开始埋雷
     butpane = new JPanel(new GridLayout(this.bwidth,this.bhight));
     butpane.setBounds(5, 10+ finalBoom.boomwidth*2, finalBoom.boomwidth*bwidth-10, finalBoom.boomwidth*bhight);
     butpane.setBorder(finalBoom.Bor1);
     
     //RightMouse rm = new RightMouse(this);
     but = new JButton[this.bwidth][this.bhight];
        for (int i = 0; i < but.length; i++) {
    for (int j = 0; j < but[i].length; j++) {
    but[i][j] = new JButton();
    butpane.add(but[i][j]);
    but[i][j].setBorder(finalBoom.Bor0);
    but[i][j].setBackground(Color.pink);
    but[i][j].addActionListener(new BoomLook(this,i,j));
    but[i][j].addMouseListener(new RightMouse(this,i,j));
   }
   
  }
     
     this.add(butpane);
     this.setVisible(true);
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

 public long getTime() {
  return time;
 }

 public void setTime(long time) {
  this.time = time;
 }

 public long getHtime() {
  return htime;
 }

 public void setHtime(long htime) {
  this.htime = htime;
 }

 public long getS() {
  return s;
 }

 public void setS(long s) {
  this.s = s;
 }

 public JButton[][] getBut() {
  return but;
 }

 public void setBut(JButton[][] but) {
  this.but = but;
 }

 public JButton getStart() {
  return start;
 }

 public void setStart(JButton start) {
  this.start = start;
 }

 public JPanel getButpane() {
  return butpane;
 }

 public void setButpane(JPanel butpane) {
  this.butpane = butpane;
 }

 public JPanel getTypepane() {
  return typepane;
 }

 public void setTypepane(JPanel typepane) {
  this.typepane = typepane;
 }

 public JTextField getNum1() {
  return num1;
 }

 public void setNum1(JTextField num1) {
  this.num1 = num1;
 }

 public JTextField getNum2() {
  return num2;
 }

 public void setNum2(JTextField num2) {
  this.num2 = num2;
 }

 public int getBoomnum() {
  return boomnum;
 }

 public void setBoomnum(int boomnum) {
  this.boomnum = boomnum;
 }

 public int getBwidth() {
  return bwidth;
 }

 public void setBwidth(int bwidth) {
  this.bwidth = bwidth;
 }

 public int getBhight() {
  return bhight;
 }

 public void setBhight(int bhight) {
  this.bhight = bhight;
 }

 public int[] getBoompost() {
  return boompost;
 }

 public void setBoompost(int[] boompost) {
  this.boompost = boompost;
 }
   
   
}
2.选择界面
package com.saolei.view;

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import java.awt.event.*;

import com.saolei.contorl.finalBoom;

public class StartFrame extends JFrame {
 private JButton low, medium, high;
 private JTextField st;
 private JLabel back;
 private JPanel menupane;

 public StartFrame() {//选择难度界面
  super("扫雷");

  this.setBounds(400, 200, 250, 300);
  this.setLayout(null);

  menupane = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
  menupane.setBounds(5, 5, 220, 250);
  this.add(menupane);
  menupane.setBorder(finalBoom.Bor1);

  low = new JButton("    幼儿园    ");
  low.addActionListener(new ActionListener() {
   @Override
   public void actionPerformed(ActionEvent e) {
    // TODO 自动生成的方法存根
    new BoomFrame(9);
    setVisible(false);
   }
  });
  medium = new JButton("    初中生    ");
  medium.addActionListener(new ActionListener() {
   @Override
   public void actionPerformed(ActionEvent e) {
    // TODO 自动生成的方法存根
    new BoomFrame(16);
    setVisible(false);
   }
  });
  high = new JButton("    大学生    ");
  high.addActionListener(new ActionListener() {
   @Override
   public void actionPerformed(ActionEvent e) {
    // TODO 自动生成的方法存根
      
    new BoomFrame(25);
    //oldFrame.dispose();
    // 关闭并销毁,无需销毁可采用oldFrame.setVisible(false);
    setVisible(false);
   }
  });
  low.setBackground(Color.blue);
  medium.setBackground(Color.pink);
  high.setBackground(Color.red);
  menupane.add(low);
  menupane.add(medium);
  menupane.add(high);
  back = new JLabel(finalBoom.logo7);
  menupane.add(back);

  this.setVisible(true);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }


 public JButton getLow() {
  return low;
 }

 public void setLow(JButton low) {
  this.low = low;
 }

 public JButton getMedium() {
  return medium;
 }

 public void setMedium(JButton medium) {
  this.medium = medium;
 }

 public JButton getHigh() {
  return high;
 }

 public void setHigh(JButton high) {
  this.high = high;
 }

 public JTextField getSt() {
  return st;
 }

 public void setSt(JTextField st) {
  this.st = st;
 }

 public JLabel getBack() {
  return back;
 }

 public void setBack(JLabel back) {
  this.back = back;
 }

 public JPanel getMenupane() {
  return menupane;
 }

 public void setMenupane(JPanel menupane) {
  this.menupane = menupane;
 }
}

你可能感兴趣的:(扫雷代码之界面(1))