扫雷项目源代码详解

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

主函数所在处

package saolei.frame;

import java.awt.BorderLayout;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JPanel;

import saolei.tools.Tools;

import saolei.menubar.Mymenubar;

import saolei.panel.MybompPanel;

import saolei.panel.MyfacePanel;

public class MymineFrame extends JFrame{

private Mymenubar mymenubar;//菜单栏

private MyfacePanel myfacePanel;//笑脸lable

private MybompPanel mybompPanel;//雷面板

private JPanel jPanel;//主面板用来装笑脸面板和雷面板

public Mymenubar getMymenubar() {

return mymenubar;

}

public void setMymenubar(Mymenubar mymenubar) { this.mymenubar = mymenubar;

}

public MyfacePanel getMyfacePanel() {

return myfacePanel;

}

public void setMyfacePanel(MyfacePanel myfacePanel) { this.myfacePanel = myfacePanel;

}

public MybompPanel getMybompPanel() {

return mybompPanel;

}

public void setMybompPanel(MybompPanel mybompPanel) { this.mybompPanel = mybompPanel;

}

public MymineFrame(String s)

{

super(s);

init();

this.add(jPanel);//将主面板装到这个Frame

this.pack();//自动设置大小

this.setVisible(true);//设置Frame可见

}

private void init() {

mymenubar=new Mymenubar(this);

myfacePanel=new MyfacePanel();

mybompPanel=new MybompPanel(this);

jPanel=new JPanel();

jPanel.setLayout(new BorderLayout());//将主面板设置为边框布局

Tools.faceLabel.addMouseListener(new MouseAdapter() {//对笑脸添加监听

public void mousePressed(MouseEvent e) {

Tools.faceLabel.setIcon(Tools.faceIcon[1]);//未释放时笑脸凹下去

}

public void mouseReleased(MouseEvent e) {

Tools.faceLabel.setIcon(Tools.faceIcon[0]);//释放时重新开局

rePlay();

}

});

this.setIconImage(new

ImageIcon("./images/icon.gif").getImage());//设置扫雷图标

this.setLocationRelativeTo(null);//设置窗口相对于指定组件的位置,因为参数为nul,所以此窗口将置于屏幕的中央

this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置在关闭时退出

this.setResizable(false);//设置不可变大小

this.setJMenuBar(mymenubar);//放入菜单

jPanel.add(myfacePanel,BorderLayout.NORTH);//放笑脸

jPanel.add(mybompPanel,BorderLayout.CENTER);//放雷区

}

public void rePlay()//重新开局函数

{

Tools.timer.stop();//时间开始,因为只能有一个计时器所以将它写在静态区

Tools.myTimerTask.time = 0;//设置开始时间为0

Tools.timeLabelB.setIcon(Tools.numberIcon[0]);

Tools.timeLabelS.setIcon(Tools.numberIcon[0]);

Tools.timeLabelG.setIcon(Tools.numberIcon[0]);

this.remove(jPanel);//移除主面板然后重新new一个

jPanel = new JPanel();

mymenubar = new Mymenubar(this);//重新定义里面元素

myfacePanel = new MyfacePanel();

Tools.setMineCount(Tools.mineCount);

Tools.faceLabel.setIcon(Tools.faceIcon[0]);

mybompPanel = new MybompPanel(this);

jPanel.setLayout(new BorderLayout());

jPanel.add(myfacePanel, BorderLayout.NORTH);

jPanel.add(mybompPanel, BorderLayout.CENTER);//重新装载组件

this.add(jPanel);

this.pack();

this.validate();//确保组件具有有效的布局

}

public static void main(String[] args) {

MymineFrame mymineFrame=new MymineFrame("扫雷");//主函数 ,函数入口}

}

雷面板

package saolei.panel;

import java.awt.Color;

import java.awt.GridLayout;

import javax.swing.BorderFactory;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.BevelBorder;

import javax.swing.border.Border;

import saolei.frame.MymineFrame;

import ble.MymineLable;

import saolei.listener.MyListener;

import saolei.tools.Tools;

相关文档
最新文档