minesweepmain.java
来自「java编写的一个小的扫雷游戏」· Java 代码 · 共 70 行
JAVA
70 行
//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 + =
减小字号Ctrl + -
显示快捷键?