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

📄 minesweepmain.java

📁 java编写的一个小的扫雷游戏
💻 JAVA
字号:
//This class is the most important class, it can form the expression of the game, and
// control all possible conditions.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MineSweepMain extends JFrame{
		private Container container = new Container();
		public  int numberOfMine = 10 ;
		public int numDisplay;
		private GridLayout gridLayout = new GridLayout(10, 10 ) ;
		private FlowLayout flowLayout =new FlowLayout(0, 50 ,0 ) ;
		private BorderLayout borderLayout = new BorderLayout(5, 5);
		private JPanel jPanel = new JPanel();
		private JPanel upjPanel  = new JPanel();
		private JButton startButton;
		public static JTextField textField;
		public static int mine =10  ;
		Icon startIcon = new ImageIcon("restart.gif");		
		
		public MineSweepMain( ){
			super("Mine Sweeper");							
			container = getContentPane(); 			 
			container.setLayout( borderLayout ) ;						
			jPanel.setLayout( gridLayout );
			upjPanel.setLayout( flowLayout );   		    
			startButton = new JButton( " New Game ",startIcon); 
			textField = new JTextField("  The remaining mines :   "+ mine +"   "  ) ;
			textField.setEditable(false);
		     upjPanel.add( startButton );
		     upjPanel.add( textField ) ;
		     startButton.addMouseListener(new MyMouseListener());	
			 container.add( upjPanel, borderLayout.NORTH );
			 container.add(  jPanel , borderLayout.CENTER ); 
		}			
		public void mineSweeperBuilt(){					
			 mine = 10 ;
		     ButtonMine application = new ButtonMine(  );	
		     application.generalBuilt(jPanel) ;		    
		     setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
			    setSize(  450, 400 );
			    setVisible( true );	
		}	
		 public static void addMine(){
		    	mine++;
		    	if ( mine < 10 )  
		    	textField.setText("  The remaining mines :   " + mine + "   " ); }
			public static void downMine(){
				    mine--;
					if ( mine < 10 )  		    	
			    	textField.setText("  The remaining mines :   "+ mine +"   "  );}		
	    private class MyMouseListener extends MouseAdapter{
			public void mouseClicked( MouseEvent event){				
				container.removeAll();
				container.setLayout( borderLayout ) ;	
				container.add( upjPanel, borderLayout.NORTH) ;
				container.add( jPanel, borderLayout.CENTER) ;
				jPanel.removeAll() ;mine = 10 ;
				textField.setText("  The remaining mines :   "+ mine +"   "  ) ;
				ButtonMine application = new ButtonMine(  );	
			    application.generalBuilt( jPanel) ;	    
			    validate();}
		   }
		public static void main( String args[] ){		 	
		   MineSweepMain app = new MineSweepMain();		  
		   app.mineSweeperBuilt();
		   app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    }
}

⌨️ 快捷键说明

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