?? sfram.java
字號:
import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class SFram extends JPanel{
private int showLeave=10;
private int realLeave=10;
private JPanel[][] lei;
private int ge;
MediaTracker mt=new MediaTracker(this);
private Saolei saolei;
SFram(int ge,Saolei saolei){
this.saolei=saolei;
this.ge=ge;
replay(ge,10);
}
SFram(Saolei saolei){
this.saolei=saolei;
this.ge=9;
replay(ge,10);
}
public void replay(int ge,int mlei){
showLeave=mlei;
realLeave=mlei;
this.removeAll();
this.setLayout(new GridLayout(ge,ge,1,1));
lei=new JPanel[ge][ge];
for(int i=0;i<ge;i++){
for(int j=0;j<ge;j++){
lei[i][j]=new JPanel();
lei[i][j].setBackground(Color.decode("#999999"));
lei[i][j].add(new JLabel(""));
lei[i][j].addMouseListener(new MouseRead(i,j,saolei));
this.add(lei[i][j]);
//lei[i][j].createImage(40,40);
lei[i][j].setSize(10,10);
}
}
//this.setSize(500,500);
}
public boolean setOpen(int x,int y,int z){
if(lei[x][y].getName()!="leibiao"){
if(z==0){
lei[x][y].removeAll();
lei[x][y].setBackground(Color.decode("#cccccc"));
saolei.reshow();
}
else if(z==9){
lei[x][y].removeAll();
lei[x][y].add(new JLabel("M"));
lei[x][y].setBackground(Color.decode("#ff0000"));
saolei.reshow();
}
else if(z<9&&z>0){
lei[x][y].removeAll();
lei[x][y].add(new JLabel(""+z+""));
lei[x][y].setBackground(Color.decode("#cccccc"));
saolei.reshow();
}
lei[x][y].setName("open");
return true;
}
else
return false;
}
public void setClose(int x,int y,int z){
if(lei[x][y].getName()!="open"){
if(lei[x][y].getName()!="leibiao"){
lei[x][y].removeAll();
lei[x][y].add(new JLabel("#"));
lei[x][y].setBackground(Color.decode("#cccc00"));
lei[x][y].setName("leibiao");
showLeave--;
if(z==1){
realLeave--;
if(realLeave==0)
saolei.win();
}
saolei.reshow();
}
else{
lei[x][y].removeAll();
lei[x][y].setBackground(Color.decode("#999999"));
lei[x][y].setName(null);
showLeave++;
if(z==1)
realLeave++;
saolei.reshow();
}
}
}
public int getShowLeave(){
return showLeave;
}
//void setBlank(int x,int y){
// if(lei[x][y])
//}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -