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

📄 cleanmine.java

📁 eclipse上的扫雷游戏的源码
💻 JAVA
字号:
package cleanmine;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;


public class CleanMine extends JFrame implements ActionListener{
	
//	 private JFrame frame ;

	 private JMenu file ,help;
	 private JLabel label1,label2;
	 private JLabel time;
	 public static JLabel remainMine;
	 private JButton restart;
	 private int col,row,mine;
	 private JPanel center;
	 public CleanMine(){
//		 frame= new JFrame("扫雷");
		
		 label1= new JLabel("剩余地雷:");
		 label2 = new JLabel("所用时间:");
		 remainMine = new JLabel("10");
		 time = new JLabel("0");
		
		 restart = new JButton("重新开始");
		 restart.addActionListener(this);
		 JMenuBar bar= new JMenuBar();;
		
		
		 
		 file = new JMenu("游戏");
		 help = new JMenu("帮助");
		 
		 JMenuItem item;
		 ButtonGroup bg = new ButtonGroup();
		 file.add(item=new JMenuItem("开始"));item.addActionListener(this);
		 file.addSeparator();
		 file.add(item=new JCheckBoxMenuItem ("低级趣味",true));bg.add(item);item.addActionListener(this);
		 file.add(item=new JCheckBoxMenuItem ("略有品位"));bg.add(item);item.addActionListener(this);
		 file.add(item=new JCheckBoxMenuItem ("极有品位"));bg.add(item);item.addActionListener(this);
		 file.add(item=new JCheckBoxMenuItem ("没有品位"));bg.add(item);item.addActionListener(this);
		 file.addSeparator();
		 file.add(item=new JMenuItem("退出"));item.addActionListener(this);
		 
		 help.add(item=new JMenuItem("帮组"));item.addActionListener(this);
		 file.addSeparator();
		 help.add(item=new JMenuItem("关于"));item.addActionListener(this);
		 
		 bar.add(file);
		 bar.add(help);
		 
		 this.setJMenuBar(bar);
		 
		 init();
		 
	 }
	 public void init(){
		 JPanel north = new JPanel();
		 
//		 north.setLayout(new FlowLayout());
		 north.add(label1);
		 north.add(remainMine);
		 north.add(restart);
		 north.add(label2);
		 north.add(time);
		 
		 this.add(north, BorderLayout.NORTH);
		 this.row=9;
			this.col=9;
			this.mine=10;
		 restart();
		 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		 new Thread(){
				public void run(){
					while(Integer.parseInt(remainMine.getText())>0){
						try {
							Thread.sleep(1000);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
						time.setText((Integer.parseInt(time.getText())+1)+"");
						
					}
				}
			}.start();
	 }

	 public void restart(){
		 if(center!=null){
				this.remove(center);
			}
			center=new AllButtonPanel2(row,col,mine);
			this.add(center,BorderLayout.CENTER);
			this.remainMine.setText(mine+"");
			
			this.time.setText("0");
			this.setSize(col*30,row*30+10);
			this.setResizable(false);
			this.setVisible(true);
	 }
	public void actionPerformed(ActionEvent e) {
		
		if(e.getActionCommand().equals("低级趣味")){
			this.row= 9;
			this.col= 9;
			this.mine = 10;
			restart();
			return;
		}
		if(e.getActionCommand().equals("略有品位")){
			this.row = 16;
			this.col = 16;
			this.mine= 40;
			restart();
			return;
		}
		if(e.getActionCommand().equals("极有品位")){
			
			this.row = 25;
			this.col= 30;
			this.mine= 70;
			restart();
			return;
		}
        if(e.getActionCommand().equals("没有品位")){
			
			this.row = 45;
			this.col= 44;
			this.mine= 200;
			restart();
			return;
		}
		if(e.getActionCommand().equals("重新开始")){
			restart();
			return;
		}
		
	}
	public static void main(String[] args) {
		new CleanMine();
//		System.out.println(AllButtonPanel.index);
	}

}

⌨️ 快捷键说明

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