?? minebutton.java
字號(hào):
/*
* MineButton.java 1.0 2003-6-15
*
* Copyleft (c) 2003 RatKing.
*/
package jmine;
import java.awt.Dimension;
import javax.swing.*;
import javax.swing.plaf.ButtonUI;
import javax.swing.border.Border;
/**
* 地雷按鈕
*
* @author <a href="ratking@ynet.com">RatKing</a>
* @version 1.0
*/
public class MineButton extends AbstractButton {
private JMine jmine;
public static final int ICON_M0 = 0;
public static final int ICON_M1 = 1;
public static final int ICON_M2 = 2;
public static final int ICON_M3 = 3;
public static final int ICON_M4 = 4;
public static final int ICON_M5 = 5;
public static final int ICON_M6 = 6;
public static final int ICON_M7 = 7;
public static final int ICON_M8 = 8;
public static final int ICON_NULL = 9;
public static final int ICON_FLAG = 10;
public static final int ICON_MARK = 11;
public static final int ICON_MINE_BLACK = 12;
public static final int ICON_MINE_ERROR = 13;
public static final int ICON_MINE_EXPLODED = 14;
private ImageIcon[] icon = new ImageIcon[15];
private int row; // 所在行
private int column; // 所在列
private boolean isMine;
private int iconStyle;
public MineButton(JMine jmine, int row, int column) {
this(jmine, row, column, false, ICON_NULL);
}
/**
* @param row 橫向坐標(biāo)
* @param column 縱向坐標(biāo)
* @param isMine 是否是地雷
* @param iconStyle 按鈕上的圖標(biāo)
*/
public MineButton(JMine jmine, int row, int column, boolean isMine, int iconStyle) {
this.jmine = jmine;
// Create the model
setModel(new DefaultButtonModel());
// initialize
init(null, null);
icon[ICON_M0] = null;
icon[ICON_M1] = jmine.createImageIcon("m1.png", "1");
icon[ICON_M2] = jmine.createImageIcon("m2.png", "2");
icon[ICON_M3] = jmine.createImageIcon("m3.png", "3");
icon[ICON_M4] = jmine.createImageIcon("m4.png", "4");
icon[ICON_M5] = jmine.createImageIcon("m5.png", "5");
icon[ICON_M6] = jmine.createImageIcon("m6.png", "6");
icon[ICON_M7] = jmine.createImageIcon("m7.png", "7");
icon[ICON_M8] = jmine.createImageIcon("m8.png", "8");
icon[ICON_NULL] = null;
icon[ICON_FLAG] = jmine.createImageIcon("flag.png", "小紅旗");
icon[ICON_MARK] = jmine.createImageIcon("mark.png", "?標(biāo)記");
icon[ICON_MINE_BLACK] = jmine.createImageIcon("mine_black.png", "黑色地雷");
icon[ICON_MINE_EXPLODED]= jmine.createImageIcon("mine_exploded.png", "爆炸的地雷");
icon[ICON_MINE_ERROR] = jmine.createImageIcon("mine_error.png", "錯(cuò)誤標(biāo)記的地雷");
this.row = row;
this.column = column;
this.isMine = isMine;
setIconStyle(iconStyle);
setPreferredSize(new Dimension(16, 16));
setFocusPainted(false);
setContentAreaFilled(false);
}
public int getRow() {
return row;
}
public int getColumn() {
return column;
}
public boolean isMine() {
return isMine;
}
public void setMine(boolean isMine) {
this.isMine = isMine;
}
/**
* 設(shè)置邊框?yàn)橥钩鰳邮? */
public void setBorderUp() {
setBorder(BorderFactory.createRaisedBevelBorder());
}
/**
* 設(shè)置邊框?yàn)榘枷聵邮? */
public void setBorderDown() {
setBorder(MineLineBorder.createBorder());
}
/**
* @return 返回圖標(biāo)類型
*/
public int getIconStyle() {
return iconStyle;
}
/**
* 設(shè)置圖像類型
*/
public void setIconStyle(int iconStyle) {
this.iconStyle = iconStyle;
Border border = (iconStyle == ICON_NULL || iconStyle == ICON_FLAG
||iconStyle == ICON_MARK)
? BorderFactory.createRaisedBevelBorder()
: MineLineBorder.createBorder();
setIcon(icon[iconStyle]);
if (iconStyle == ICON_NULL || iconStyle == ICON_FLAG
||iconStyle == ICON_MARK) {
setBorder(BorderFactory.createRaisedBevelBorder());
}
else {
setBorder(MineLineBorder.createBorder());
}
//repaint();
}
/**
* Resets the UI property to a value from the current look and
* feel.
*
* @see JComponent#updateUI
*/
public void updateUI() {
setUI((ButtonUI)UIManager.getUI(this));
}
private static final String uiClassID = "ButtonUI";
/**
* Returns a string that specifies the name of the L&F class
* that renders this component.
*
* @return the string "ButtonUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
* @beaninfo
* expert: true
* description: A string that specifies the name of the L&F class.
*/
public String getUIClassID() {
return uiClassID;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -