📄 minebutton.java
字号:
//组件类~专门为扫雷的按钮设计---the button class designed for minesweeper
import javax.swing.*;
import java.awt.Insets;
public class MineButton extends JButton{
static public int opened=0; //统计已经打开了多少雷---the number of opened mines
//以按钮的位置初始化---initialize the button by its position
final static String[] button_colour={"0033CC","006600","FF0000","000033","660000","3FB7FE","000000","666666"};//color of the button
public MineButton(int i,int j) {
row=i;
colum=j;
this.setMargin(new Insets(0,0,0,0));
this.setFocusable(false);
}
public int colum;
public int row;
//状态 0是关着,1是显示---the state of this button:0 for close(able),1 for open(unable)
public int state=0;
//周围雷的信息,可以是012345678 -1代表本身就是雷---the number of mines around this button(it can be 012345678,-1 represent it is a mine)
public int mines;
//显示雷数,并把自己设定为不可用---show my mines,and set myself unable
public void lockthis()
{
Icon ico=new ImageIcon("src\\-1.gif");
if(state==0){
opened++;
state=1;
if(mines==-1)
//this.setText("#");
{this.setIcon(ico);
return;
}
else if(mines!=0)
this.setText("<html><p style='color:#"+button_colour[mines-1]+"'>"+mines);
this.setIcon(null);
this.setEnabled(false);
}
}
//隐藏雷的信息,并把自己设为可点击---hide my mines,and set myself be able to be clicked
public void unlockthis()
{
this.setText("");
this.setIcon(null);
state=0;
this.setEnabled(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -