.
import java.awt.BorderLayout; import java.awt.Container; import java.awt.Font; import java.awt.GridLayout; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.Timer;
public class ScanLei1 extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L; private Container contentPane; private JButton btn; private JButton[] btns; private JLabel b1; private JLabel b2; private JLabel b3; private Timer timer; private int row=9; private int col=9; private int bon=10; private int[][] a; private int b; private int[] a1;
private JPanel p,p1,p2,p3;
public ScanLei1(String title){
super(title);
contentPane=getContentPane(); setSize(297,377);
this.setBounds(400, 100, 400, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); timer =new Timer(1000,(ActionListener) this); a = new int[row+2][col+2];
.
.
}
initGUI();
public void initGUI(){ p3=new JPanel();
b=bon;
JMenuBar menuBar=new JMenuBar(); JMenu menu1=new JMenu(\游戏\); JMenu menu2=new JMenu(\帮助\); JMenuItem mi1=new JMenuItem(\初级\); JMenuItem mi2 = new JMenuItem(\中级\); JMenuItem mi3 =new JMenuItem(\高级\); mi1.addActionListener(this); menu1.add(mi1);
mi2.addActionListener(this); menu1.add(mi2);
mi3.addActionListener(this); menu1.add(mi3); menuBar.add(menu1); menuBar.add(menu2); p3.add(menuBar); b1=new JLabel(bon+\); a1=new int[bon];
btn =new JButton(\开始\); btn.addActionListener(this); b2=new JLabel(\); b3=new JLabel(\);
btns=new JButton[row*col]; p=new JPanel();
p.setLayout(new BorderLayout()); contentPane.add(p);
p.add(p3,BorderLayout.NORTH);
//combo=new JComboBox(new Object[]{\初级\中级\高级\ //加监听
/*combo.addItemListener(new ItemListener(){
}});*/ p1=new JPanel(); //在那个位置
//(( FlowLayout)p1.getLayout()).setAlignment( FlowLayout.RIGHT); p1.add(b1); p1.add(btn); p1.add(b2); p1.add(b3);
p.add(p3,BorderLayout.NORTH);
.
.
}
p.add(p1,BorderLayout.CENTER); p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0)); for(int i=0;i contentPane.add(p,BorderLayout.NORTH); contentPane.add(p2,BorderLayout.CENTER); btns[i]=new JButton(\); btns[i].setMargin(new Insets(0,0,0,0)); btns[i].setFont(new Font(null,Font.BOLD,25)); btns[i].addActionListener(this); btns[i].addMouseListener(new NormoreMouseEvent()); p2.add(btns[i]); public void go(){ } setVisible(true); public static void main(String[] args){ } public void out(int[][] a,JButton[] btns,ActionEvent e,int i,int x,int y){ int p=1; if(a[x][y]==0){ a[x][y]=10; new ScanLei1(\扫雷\).go(); btns[i].setEnabled(false); //33 for(int l=y-1;l<=y+1;l++){ int m=x-1-1; int n=l-1; p=1; System.out.println(a[1][2]); if(n>-1&&n for(int q=0;q if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){ if(a[x-1][l]!=0&&a[x-1][l]!=10){ btns[n+col*q].setText(a[x-1][l]+\); a[x-1][l]=10; btns[n+col*q].setEnabled(false); } else if(a[x-1][l]==0){ //a[x-1][l]=10; btns[n+col*q].setEnabled(false); out(a,btns,e,n+col*q,x-1,l); ////55//// a[x-1][l]=10; . . } btns[n+col*q].setEnabled(false); } p=0; } } p=1; m=x; if(n>-1&&n if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){ if(a[x+1][l]!=0&&a[x+1][l]!=10){ for(int q=0;q btns[n+col*q].setText(a[x+1][l]+\); a[x+1][l]=10; btns[n+col*q].setEnabled(false); } else if(a[x+1][l]==0){ } } out(a,btns,e,n+col*q,x+1,l);///55//// a[x+1][l]=10; btns[n+col*q].setEnabled(false); p=0; } } } int m=x-1; int n=y-1-1; p=1; if(n>-1&&n { if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){ if(a[x][y-1]!=0&&a[x][y-1]!=10){ for(int q=0;q btns[n+col*q].setText(a[x][y-1]+\); a[x][y-1]=10; btns[n+col*q].setEnabled(false); } else if(a[x][y-1]==0){ . . } } out(a,btns,e,n+col*q,x,y-1); a[x][y-1]=10; btns[n+col*q].setEnabled(false); p=0; } } p=1; m=x-1; n=y+1-1; if(n>-1&&n public void actionPerformed(ActionEvent e) { if(e.getActionCommand()==\初级\){ row=9; col=9; bon=10; a1=new int[bon]; b=bon; //setSize(297,377); } { } if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){ if(a[x][y+1]!=0&&a[x][y+1]!=10){ for(int q=0;q btns[n+col*q].setText(a[x][y+1]+\); a[x][y+1]=10; btns[n+col*q].setEnabled(false); } else if(a[x][y+1]==0){ } out(a,btns,e,n+col*q,x,y+1); btns[n+col*q].setEnabled(false); a[x][y+1]=10; } p=0; } .