import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class sao {
sao(){
JFrame f_main = new JFrame("扫雷");
f_main.setSize(300,300); JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JTextField jt1 = new JTextField("0",5);
JTextField jt2 = new JTextField("10",5);
JButton jb = new JButton("开始");
JMenuBar menub = new JMenuBar();
JMenu j1=new JMenu("游戏");
JMenu j2=new JMenu("帮助");
JMenu j3=new JMenu("关于作者");
JMenuItem jm1=new JMenuItem("初级");
JMenuItem jm2=new JMenuItem("中级");
JMenuItem jm3=new JMenuItem("高级");
JMenuItem jm4=new JMenuItem("开局");
JMenuItem jm5=new JMenuItem("退出");
JMenuItem jm6=new JMenuItem("帮助");
JMenuItem jm7=new JMenuItem("扫雷游戏"); menub.add(j1); //向菜单栏中添加菜单
menub.add(j2);
menub.add(j3); j1.add(jm4);
j1.addSeparator();
j1.add(jm1);
j1.add(jm2);
j1.add(jm3);
j1.addSeparator();
j1.add(jm5);
j2.add(jm6);
j3.add(jm7);
f_main.setJMenuBar(menub);
JDialog d1 = new JDialog(f_main,"恭喜",true);
JButton b1 = new JButton("确定");
JLabel l1 = new JLabel("恭喜通关,再来一局吗?"); d1.add(l1,"Center");
d1.add(b1);
d1.setVisible(false); jp2.setLayout(new GridLayout(9,9));
jp1.setBackground(Color.orange);
jp1.setSize(300,50);
jp2.setBackground(Color.gray);
jp1.setSize(300,200);
JButton jb1[][] = new JButton[9][9];
for(int i =0;i < 9;i++)
for(int j = 0;j < 9;j++){
jb1[i][j]=new JButton();
}
for(int n =0;n < 9;n++)
for(int m = 0;m < 9;m++){
jp2.add(jb1[n][m]);
}
jp3.add(jp1);
jp3.add(jp2);
jp1.add(jt1);
jp1.add(jb);
jp1.add(jt2);
f_main.add(jp3);
f_main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f_main.setVisible(true); jm6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "本人初学,参照课本资料和网上实例编写,请多多指教","帮助主题",JOptionPane.PLAIN_MESSAGE);
}
}); jm7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"此游戏仿制Windows中的扫雷程序而写,具体请参照Window扫雷!","扫雷游戏",JOptionPane.PLAIN_MESSAGE);
}
}); jm5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});}
void bulei(){
public boolean isBomb; isBomb = false;
for(int i=0;i<9;i++)
{
int x =(int)(Math.random()*9);
int y =(int)(Math.random()*9);
if(jb1[ x ][ y ].isBomb==true)
i--;
else
jb1[ x ][ y ].isBomb=true ;
}
} public static void main(String[] argus)
{
new sao();
}
}
import java.awt.*;
import java.awt.event.*;
public class sao {
sao(){
JFrame f_main = new JFrame("扫雷");
f_main.setSize(300,300); JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JTextField jt1 = new JTextField("0",5);
JTextField jt2 = new JTextField("10",5);
JButton jb = new JButton("开始");
JMenuBar menub = new JMenuBar();
JMenu j1=new JMenu("游戏");
JMenu j2=new JMenu("帮助");
JMenu j3=new JMenu("关于作者");
JMenuItem jm1=new JMenuItem("初级");
JMenuItem jm2=new JMenuItem("中级");
JMenuItem jm3=new JMenuItem("高级");
JMenuItem jm4=new JMenuItem("开局");
JMenuItem jm5=new JMenuItem("退出");
JMenuItem jm6=new JMenuItem("帮助");
JMenuItem jm7=new JMenuItem("扫雷游戏"); menub.add(j1); //向菜单栏中添加菜单
menub.add(j2);
menub.add(j3); j1.add(jm4);
j1.addSeparator();
j1.add(jm1);
j1.add(jm2);
j1.add(jm3);
j1.addSeparator();
j1.add(jm5);
j2.add(jm6);
j3.add(jm7);
f_main.setJMenuBar(menub);
JDialog d1 = new JDialog(f_main,"恭喜",true);
JButton b1 = new JButton("确定");
JLabel l1 = new JLabel("恭喜通关,再来一局吗?"); d1.add(l1,"Center");
d1.add(b1);
d1.setVisible(false); jp2.setLayout(new GridLayout(9,9));
jp1.setBackground(Color.orange);
jp1.setSize(300,50);
jp2.setBackground(Color.gray);
jp1.setSize(300,200);
JButton jb1[][] = new JButton[9][9];
for(int i =0;i < 9;i++)
for(int j = 0;j < 9;j++){
jb1[i][j]=new JButton();
}
for(int n =0;n < 9;n++)
for(int m = 0;m < 9;m++){
jp2.add(jb1[n][m]);
}
jp3.add(jp1);
jp3.add(jp2);
jp1.add(jt1);
jp1.add(jb);
jp1.add(jt2);
f_main.add(jp3);
f_main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f_main.setVisible(true); jm6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "本人初学,参照课本资料和网上实例编写,请多多指教","帮助主题",JOptionPane.PLAIN_MESSAGE);
}
}); jm7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"此游戏仿制Windows中的扫雷程序而写,具体请参照Window扫雷!","扫雷游戏",JOptionPane.PLAIN_MESSAGE);
}
}); jm5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});}
void bulei(){
public boolean isBomb; isBomb = false;
for(int i=0;i<9;i++)
{
int x =(int)(Math.random()*9);
int y =(int)(Math.random()*9);
if(jb1[ x ][ y ].isBomb==true)
i--;
else
jb1[ x ][ y ].isBomb=true ;
}
} public static void main(String[] argus)
{
new sao();
}
}
不懂可以看看这个,也是Java扫雷
http://blog.csdn.net/kakashi8841/archive/2010/11/17/6014036.aspx
JButton jb1[][] = new JButton[9][9];
public boolean isBomb;
isBomb=false;
sao(){
。。
我把它改成这样的了,可是提示说isBomb=false;需要标识符,为什么的呀?