接上1public void xiao()
{
if(((x0==x)&&(y0==y+1||y0==y-1))||((x0==x+1||x0==x-1)&&(y0==y)))
{//判断是否相邻
remove();
}
else
{
for(j=0;j<v;j++)
{ //行的时候
if(grid[x0][j]==0)
{//判断第一个按钮同行的哪个按钮为空
if(y>j)
{//如果第二个按钮的Y坐标大于控按钮的Y坐标说明第一按钮在空左边
for(i=y-1;i>=j;i--)
{//判断第二空按钮中间还有无按钮
if (grid[x][i]!=0) //第二个按钮的行,在第二空个按钮中间无空按钮
{
k=0;
break;
}
else{k=1;}
}
if(k==1)
{
linePassOne(); //判断第一个按钮的
}
}
if(y<j)
{
for(i=y+1;i<=j;i++)
{
if(grid[x][i]!=0)
{
k=0;
break;
}
else{k=1;}
}
if(k==1)
{
linePassOne();
}
}
if(y==j)
{
linePassOne();
}
}
if(k==2) //当第一个按钮与空按钮中间无按钮
{
if(x0==x) //第一二个按钮在同一行
{
remove();
}
if(x0<x) //如果第一个按钮在第二个下方
{
for(n=x0;n<=x-1;n++)
{//判断列上第一二个按钮中间有无按钮
if(grid[n][j]!=0)
{
k=0;
break;
}
if(grid[n][j]==0&&n==x-1)
{
remove();
}
}
}
if(x0>x) //如果第一个按钮在第二个的下方
{
for(n=x0;n>=x+1;n--)
{
if(grid[n][j]!=0)
{
k=0;
break;
}
if(grid[n][j]==0&&n==x+1)
{
remove();
}
}
}
}
}
for(i=0;i<u;i++)
{//列
if(grid[i][y0]==0)
{
if(x>i)
{
for(j=x-1;j>=i;j--)
{
if(grid[j][y]!=0)
{
k=0;
break;
}
else {k=1;}
}
if(k==1)
{
rowPassOne();
}
}
if(x<i)
{
for(j=x+1;j<=i;j++)
{
if(grid[j][y]!=0)
{
k=0;
break;
}
else {k=1;}
}
if(k==1)
{
rowPassOne();
}
}
if(x==i)
{
rowPassOne();
}
}
if(k==2)
{
if(y0==y)
{
remove();
}
if(y0<y)
{
for(n=y0;n<=y-1;n++)
{
if(grid[i][n]!=0)
{
k=0;
break;
}
if(grid[i][n]==0&&n==y-1)
{
remove();
}
}
}
if(y0>y)
{
for(n=y0;n>=y+1;n--)
{
if(grid[i][n]!=0)
{
k=0;
break;
}
if(grid[i][n]==0&&n==y+1)
{
remove();
}
}
}
}
}
}
}
public void linePassOne()
{//判断第一个按钮与空按钮中间是否有按钮
if(y0>j)
{
for(i=y0-1;i>=j;i--)
{
if(grid[x0][i]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
if(y0<j)
{
for(i=y0+1;i<=j;i++)
{
if(grid[x0][i]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
}
public void rowPassOne()
{
if(x0>i)
{
for(j=x0-1;j>=i;j--)
{
if(grid[j][y0]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
if (x0<i)
{
for(j=x0+1;j<=i;j++)
{
if(grid[j][y0]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
}
public void remove()
{
firstButton.setVisible(false);
secondButton.setVisible(false);
pressInformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jmenuitem1)
{
jpanel.setVisible(true);
jlabel2.setVisible(false);
down=new CountDown();
add(down);
down.setBounds(330,500,80,40);
jmenuitem1.removeActionListener(this);
}
if(e.getSource()==jmenuitem6)
{
JOptionPane.showMessageDialog(this," 连续点击两个按钮\n若一个为中文,一个为英\n文并意思对应,若可以用\n不超过两个拐角的连线连\n接,就消失,不然不消失!" ,"游戏说明",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==jmenuitem7)
{
JOptionPane.showMessageDialog(this," 游戏制作人","关于我们",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==jmenuitem5)
{
System.exit(0);
}
if(e.getSource()==jmenuitem3)
{
jpanel.setVisible(false);
dialog.setVisible(true);
resetJPanel();
remove(down);
CountDown down=new CountDown();
this.down=down;
add(down);
down.setBounds(330,500,80,40);
jpanel.setVisible(true);
}
if(e.getSource()==jmenuitem2)
{
resetJPanel();
jlabel2.setVisible(false);
remove(down);
CountDown down=new CountDown();
this.down=down;
add(down);
down.setBounds(330,500,80,40);
}
for(int cols=0;cols<6;cols++)
{
for(int rows=0;rows<6;rows++)
{
if(e.getSource()==diamondsButton[cols][rows])
estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);
}
}
}
}
class MyDialog extends Dialog implements ActionListener,ItemListener
{
static final int dif=1,gen=0,eas=-1;
Checkbox box1,box2,box3;
CheckboxGroup box;
Button button;
int message=-1;
MyDialog(Frame f,String s,boolean b)
{
super(f,s,b);
box=new CheckboxGroup();
button=new Button("确定");
button.addActionListener(this);
box1=new Checkbox("难",false,box);
box1.addItemListener(this);
box2=new Checkbox("中",false,box);
box2.addItemListener(this);
box3=new Checkbox("易",true,box);
box3.addItemListener(this);
add(box1);
add(box2);
add(box3);
add(button);
setLayout(new FlowLayout());
setBounds(230,200,150,100);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==box1)
{
message=dif;
}
if(e.getSource()==box2)
{
message=gen;
}
if(e.getSource()==box3)
{
message=eas;
} }
public int getMessage()
{
return message;
}
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
}
class MyPanel extends JPanel implements ActionListener
{
JLabel label;
Timer time;
MyPanel()
{
label=new JLabel();
time=new Timer(1000,this);
add(label);
setSize(100,80);
setVisible(true);
time.start();
}
public void actionPerformed(ActionEvent e)
{
java.util.Date date=new java.util.Date();
String str=date.toString().substring(11,19);
label.setText("北京时间:"+str);
label.setFont(new Font("宋体", Font.BOLD,15));
label.setForeground(Color.RED);
}
}
class CountDown extends JPanel implements ActionListener
{
int n;
JLabel label;
Timer time;
CountDown()
{
label=new JLabel();
label.setFont(new Font("宋体", Font.BOLD,20));
label.setForeground(Color.RED);
label.setText("120");
time=new Timer(1000,this);
setSize(60,80);
setLayout(new FlowLayout());
add(label,FlowLayout.LEFT);
setVisible(true);
time.start();
}
public void actionPerformed(ActionEvent e)
{
int p=10;
n=Integer.parseInt(label.getText());
n=n-1;
label.setText(String.valueOf(n));
if(n==0)
{
time.stop();
JOptionPane.showMessageDialog(this,"对不起,时间到了","提示",JOptionPane.INFORMATION_MESSAGE);
}
}
}还没弄完,因为找不出错,玩不成,所以没有继续。请高手们帮帮忙啊
{
if(((x0==x)&&(y0==y+1||y0==y-1))||((x0==x+1||x0==x-1)&&(y0==y)))
{//判断是否相邻
remove();
}
else
{
for(j=0;j<v;j++)
{ //行的时候
if(grid[x0][j]==0)
{//判断第一个按钮同行的哪个按钮为空
if(y>j)
{//如果第二个按钮的Y坐标大于控按钮的Y坐标说明第一按钮在空左边
for(i=y-1;i>=j;i--)
{//判断第二空按钮中间还有无按钮
if (grid[x][i]!=0) //第二个按钮的行,在第二空个按钮中间无空按钮
{
k=0;
break;
}
else{k=1;}
}
if(k==1)
{
linePassOne(); //判断第一个按钮的
}
}
if(y<j)
{
for(i=y+1;i<=j;i++)
{
if(grid[x][i]!=0)
{
k=0;
break;
}
else{k=1;}
}
if(k==1)
{
linePassOne();
}
}
if(y==j)
{
linePassOne();
}
}
if(k==2) //当第一个按钮与空按钮中间无按钮
{
if(x0==x) //第一二个按钮在同一行
{
remove();
}
if(x0<x) //如果第一个按钮在第二个下方
{
for(n=x0;n<=x-1;n++)
{//判断列上第一二个按钮中间有无按钮
if(grid[n][j]!=0)
{
k=0;
break;
}
if(grid[n][j]==0&&n==x-1)
{
remove();
}
}
}
if(x0>x) //如果第一个按钮在第二个的下方
{
for(n=x0;n>=x+1;n--)
{
if(grid[n][j]!=0)
{
k=0;
break;
}
if(grid[n][j]==0&&n==x+1)
{
remove();
}
}
}
}
}
for(i=0;i<u;i++)
{//列
if(grid[i][y0]==0)
{
if(x>i)
{
for(j=x-1;j>=i;j--)
{
if(grid[j][y]!=0)
{
k=0;
break;
}
else {k=1;}
}
if(k==1)
{
rowPassOne();
}
}
if(x<i)
{
for(j=x+1;j<=i;j++)
{
if(grid[j][y]!=0)
{
k=0;
break;
}
else {k=1;}
}
if(k==1)
{
rowPassOne();
}
}
if(x==i)
{
rowPassOne();
}
}
if(k==2)
{
if(y0==y)
{
remove();
}
if(y0<y)
{
for(n=y0;n<=y-1;n++)
{
if(grid[i][n]!=0)
{
k=0;
break;
}
if(grid[i][n]==0&&n==y-1)
{
remove();
}
}
}
if(y0>y)
{
for(n=y0;n>=y+1;n--)
{
if(grid[i][n]!=0)
{
k=0;
break;
}
if(grid[i][n]==0&&n==y+1)
{
remove();
}
}
}
}
}
}
}
public void linePassOne()
{//判断第一个按钮与空按钮中间是否有按钮
if(y0>j)
{
for(i=y0-1;i>=j;i--)
{
if(grid[x0][i]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
if(y0<j)
{
for(i=y0+1;i<=j;i++)
{
if(grid[x0][i]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
}
public void rowPassOne()
{
if(x0>i)
{
for(j=x0-1;j>=i;j--)
{
if(grid[j][y0]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
if (x0<i)
{
for(j=x0+1;j<=i;j++)
{
if(grid[j][y0]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
}
public void remove()
{
firstButton.setVisible(false);
secondButton.setVisible(false);
pressInformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jmenuitem1)
{
jpanel.setVisible(true);
jlabel2.setVisible(false);
down=new CountDown();
add(down);
down.setBounds(330,500,80,40);
jmenuitem1.removeActionListener(this);
}
if(e.getSource()==jmenuitem6)
{
JOptionPane.showMessageDialog(this," 连续点击两个按钮\n若一个为中文,一个为英\n文并意思对应,若可以用\n不超过两个拐角的连线连\n接,就消失,不然不消失!" ,"游戏说明",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==jmenuitem7)
{
JOptionPane.showMessageDialog(this," 游戏制作人","关于我们",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==jmenuitem5)
{
System.exit(0);
}
if(e.getSource()==jmenuitem3)
{
jpanel.setVisible(false);
dialog.setVisible(true);
resetJPanel();
remove(down);
CountDown down=new CountDown();
this.down=down;
add(down);
down.setBounds(330,500,80,40);
jpanel.setVisible(true);
}
if(e.getSource()==jmenuitem2)
{
resetJPanel();
jlabel2.setVisible(false);
remove(down);
CountDown down=new CountDown();
this.down=down;
add(down);
down.setBounds(330,500,80,40);
}
for(int cols=0;cols<6;cols++)
{
for(int rows=0;rows<6;rows++)
{
if(e.getSource()==diamondsButton[cols][rows])
estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);
}
}
}
}
class MyDialog extends Dialog implements ActionListener,ItemListener
{
static final int dif=1,gen=0,eas=-1;
Checkbox box1,box2,box3;
CheckboxGroup box;
Button button;
int message=-1;
MyDialog(Frame f,String s,boolean b)
{
super(f,s,b);
box=new CheckboxGroup();
button=new Button("确定");
button.addActionListener(this);
box1=new Checkbox("难",false,box);
box1.addItemListener(this);
box2=new Checkbox("中",false,box);
box2.addItemListener(this);
box3=new Checkbox("易",true,box);
box3.addItemListener(this);
add(box1);
add(box2);
add(box3);
add(button);
setLayout(new FlowLayout());
setBounds(230,200,150,100);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==box1)
{
message=dif;
}
if(e.getSource()==box2)
{
message=gen;
}
if(e.getSource()==box3)
{
message=eas;
} }
public int getMessage()
{
return message;
}
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
}
class MyPanel extends JPanel implements ActionListener
{
JLabel label;
Timer time;
MyPanel()
{
label=new JLabel();
time=new Timer(1000,this);
add(label);
setSize(100,80);
setVisible(true);
time.start();
}
public void actionPerformed(ActionEvent e)
{
java.util.Date date=new java.util.Date();
String str=date.toString().substring(11,19);
label.setText("北京时间:"+str);
label.setFont(new Font("宋体", Font.BOLD,15));
label.setForeground(Color.RED);
}
}
class CountDown extends JPanel implements ActionListener
{
int n;
JLabel label;
Timer time;
CountDown()
{
label=new JLabel();
label.setFont(new Font("宋体", Font.BOLD,20));
label.setForeground(Color.RED);
label.setText("120");
time=new Timer(1000,this);
setSize(60,80);
setLayout(new FlowLayout());
add(label,FlowLayout.LEFT);
setVisible(true);
time.start();
}
public void actionPerformed(ActionEvent e)
{
int p=10;
n=Integer.parseInt(label.getText());
n=n-1;
label.setText(String.valueOf(n));
if(n==0)
{
time.stop();
JOptionPane.showMessageDialog(this,"对不起,时间到了","提示",JOptionPane.INFORMATION_MESSAGE);
}
}
}还没弄完,因为找不出错,玩不成,所以没有继续。请高手们帮帮忙啊
先把你整理一下..public void xiao()
{
if(((x0==x)&&(y0==y+1||y0==y-1))||((x0==x+1||x0==x-1)&&(y0==y)))
{//判断是否相邻
remove();
}
else
{
for(j=0;j<v;j++)
{ //行的时候
if(grid[x0][j]==0)
{//判断第一个按钮同行的哪个按钮为空
if(y>j)
{//如果第二个按钮的Y坐标大于控按钮的Y坐标说明第一按钮在空左边
for(i=y-1;i>=j;i--)
{//判断第二空按钮中间还有无按钮
if (grid[x][i]!=0) //第二个按钮的行,在第二空个按钮中间无空按钮
{
k=0;
break;
}
else{k=1;}
}
if(k==1)
{
linePassOne(); //判断第一个按钮的
}}
if(y<j)
{
for(i=y+1;i<=j;i++)
{
if(grid[x][i]!=0)
{
k=0;
break;
}
else{k=1;}
}
if(k==1)
{
linePassOne();
}
}
if(y==j)
{
linePassOne();
}
}
if(k==2) //当第一个按钮与空按钮中间无按钮
{
if(x0==x) //第一二个按钮在同一行
{
remove();
}
if(x0<x) //如果第一个按钮在第二个下方
{
for(n=x0;n<=x-1;n++)
{//判断列上第一二个按钮中间有无按钮
if(grid[n][j]!=0)
{
k=0;
break;
}
if(grid[n][j]==0&&n==x-1)
{
remove();
}
}
}
if(x0>x) //如果第一个按钮在第二个的下方
{
for(n=x0;n>=x+1;n--)
{
if(grid[n][j]!=0)
{
k=0;
break;
}
if(grid[n][j]==0&&n==x+1)
{
remove();
}
}
}
}
}
for(i=0;i<u;i++)
{//列
if(grid[i][y0]==0)
{
if(x>i)
{
for(j=x-1;j>=i;j--)
{
if(grid[j][y]!=0)
{
k=0;
break;
}
else {k=1;}
}
if(k==1)
{
rowPassOne();
}
}
if(x<i)
{
for(j=x+1;j<=i;j++)
{
if(grid[j][y]!=0)
{
k=0;
break;
}
else {k=1;}
}
if(k==1)
{
rowPassOne();
}
}
if(x==i)
{
rowPassOne();
}
}
if(k==2)
{
if(y0==y)
{
remove();
}
if(y0<y)
{
for(n=y0;n<=y-1;n++)
{
if(grid[i][n]!=0)
{
k=0;
break;
}
if(grid[i][n]==0&&n==y-1)
{
remove();
}
}
}
if(y0>y)
{
for(n=y0;n>=y+1;n--)
{
if(grid[i][n]!=0)
{
k=0;
break;
}
if(grid[i][n]==0&&n==y+1)
{
remove();
}
}
}
}
}
}
}
public void linePassOne()
{//判断第一个按钮与空按钮中间是否有按钮
if(y0>j)
{for(i=y0-1;i>=j;i--)
{
if(grid[x0][i]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
if(y0<j)
{
for(i=y0+1;i<=j;i++)
{
if(grid[x0][i]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
}
public void rowPassOne()
{
if(x0>i)
{
for(j=x0-1;j>=i;j--)
{
if(grid[j][y0]!=0)
{
k=0;
break;
}
else {k=2;}
}
} if (x0<i)
{
for(j=x0+1;j<=i;j++)
{
if(grid[j][y0]!=0)
{
k=0;
break;
}
else {k=2;}
}
}
}
public void remove()
{
firstButton.setVisible(false);
secondButton.setVisible(false);
pressInformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jmenuitem1)
{
jpanel.setVisible(true);
jlabel2.setVisible(false);
down=new CountDown();
add(down);
down.setBounds(330,500,80,40);
jmenuitem1.removeActionListener(this);
}
if(e.getSource()==jmenuitem6)
{
JOptionPane.showMessageDialog(this," 连续点击两个按钮\n若一个为中文,一个为英\n文并意思对应,若可以用\n不超过两个拐角的连线连\n接,就消失,不然不消失!" ,"游戏说明",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==jmenuitem7)
{
JOptionPane.showMessageDialog(this," 游戏制作人","关于我们",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==jmenuitem5)
{
System.exit(0);
}
if(e.getSource()==jmenuitem3)
{
jpanel.setVisible(false);
dialog.setVisible(true);
resetJPanel();
remove(down);
CountDown down=new CountDown();
this.down=down;
add(down);
down.setBounds(330,500,80,40);
jpanel.setVisible(true);
}
if(e.getSource()==jmenuitem2)
{
resetJPanel();
jlabel2.setVisible(false);
remove(down);
CountDown down=new CountDown();
this.down=down;
add(down);
down.setBounds(330,500,80,40);
}
for(int cols=0;cols<6;cols++)
{
for(int rows=0;rows<6;rows++)
{
if(e.getSource()==diamondsButton[cols][rows])
estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);
}
}
}}
class MyDialog extends Dialog implements ActionListener,ItemListener
{
static final int dif=1,gen=0,eas=-1;
Checkbox box1,box2,box3;
CheckboxGroup box;
Button button;
int message=-1;
MyDialog(Frame f,String s,boolean b)
{
super(f,s,b);
box=new CheckboxGroup();
button=new Button("确定");
button.addActionListener(this);
box1=new Checkbox("难",false,box);
box1.addItemListener(this);
box2=new Checkbox("中",false,box);
box2.addItemListener(this);
box3=new Checkbox("易",true,box);
box3.addItemListener(this);
add(box1);
add(box2);
add(box3);
add(button);
setLayout(new FlowLayout());
setBounds(230,200,150,100);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==box1)
{
message=dif;
}
if(e.getSource()==box2)
{
message=gen;
}
if(e.getSource()==box3)
{
message=eas;
}}
public int getMessage()
{
return message;
}
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
}
class MyPanel extends JPanel implements ActionListener
{
JLabel label;
Timer time;
MyPanel()
{
label=new JLabel();
time=new Timer(1000,this);
add(label);
setSize(100,80);
setVisible(true);
time.start();
}
public void actionPerformed(ActionEvent e)
{
java.util.Date date=new java.util.Date();
String str=date.toString().substring(11,19);
label.setText("北京时间:"+str);
label.setFont(new Font("宋体", Font.BOLD,15));
label.setForeground(Color.RED);
}
}
class CountDown extends JPanel implements ActionListener
{
int n;
JLabel label;
Timer time;
CountDown()
{
label=new JLabel();
label.setFont(new Font("宋体", Font.BOLD,20));
label.setForeground(Color.RED);
label.setText("120");
time=new Timer(1000,this);
setSize(60,80);
setLayout(new FlowLayout());
add(label,FlowLayout.LEFT);
setVisible(true);
time.start();
}
public void actionPerformed(ActionEvent e)
{
int p=10;
n=Integer.parseInt(label.getText());
n=n-1;
label.setText(String.valueOf(n));
if(n==0)
{
time.stop();
JOptionPane.showMessageDialog(this,"对不起,时间到了","提示",JOptionPane.INFORMATION_MESSAGE);
}
}
}