?? facebutton.java
字號(hào):
/* FaceButton.java 1.0 2003-6-15
*
* Copyleft (c) 2003 RatKing.
*/
package jmine;
import java.awt.AWTEvent;
import java.awt.Dimension;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.ButtonUI;
/**
* 笑臉按鈕
*
* @author <a href="ratking@ynet.com">RatKing</a>
* @version 1.0
*/
public class FaceButton extends AbstractButton /*implements MouseListener*/ {
private JMine jmine;
public static final int FACE_SMILE = 0;
public static final int FACE_O = 1;
public static final int FACE_WIN = 2;
public static final int FACE_LOSE = 3;
private ImageIcon[] icon = new ImageIcon[4];
private int iconStyle;
private ImageIcon myIcon;
private static final Border raisedBevelBorder
= new CompoundBorder(LineBorder.createGrayLineBorder(),
BorderFactory.createRaisedBevelBorder());
private static final Border loweredBevelBorder
= new CompoundBorder(LineBorder.createGrayLineBorder(),
MineLineBorder.createBorder());
public FaceButton(JMine jmine) {
this(jmine, FACE_SMILE);
}
public FaceButton(JMine jmine, int iconStyle) {
this.jmine = jmine;
icon[FACE_SMILE]= jmine.createImageIcon("face_smile.png", "笑臉");
icon[FACE_O] = jmine.createImageIcon("face_o.png", "吃啦?");
icon[FACE_WIN] = jmine.createImageIcon("face_win.png", "戴眼鏡");
icon[FACE_LOSE] = jmine.createImageIcon("face_lose.png", "苦臉");
// Create the model
setModel(new DefaultButtonModel());
// initialize
init(null, null);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
setIconStyle(iconStyle);
setBorderUp();
setFocusPainted(false);
setContentAreaFilled(false);
Dimension d = new Dimension(26, 26);
setPreferredSize(d);
setMinimumSize(d);
setMaximumSize(d);
}
/**
* 設(shè)置邊框?yàn)橥钩鰳邮? */
public void setBorderUp() {
setBorder(raisedBevelBorder);
}
/**
* 設(shè)置邊框?yàn)榘枷聵邮? */
public void setBorderDown() {
setBorder(loweredBevelBorder);
}
public void setIconStyle(int iconStyle) {
this.iconStyle = iconStyle;
setIcon(icon[iconStyle]);
}
/**
* 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;
}
/** 重載對(duì)鼠標(biāo)事件的處理 */
protected void processMouseEvent(MouseEvent e) {
super.processMouseEvent(e);
if ((e.getID() == MouseEvent.MOUSE_PRESSED && e.getButton() == MouseEvent.BUTTON1)
|| (e.getID() == MouseEvent.MOUSE_ENTERED
&& (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == InputEvent.BUTTON1_DOWN_MASK)) {
// 按鈕凹下去
setBorderDown();
}
else if ((e.getID() == MouseEvent.MOUSE_RELEASED
&& ((e.getModifiersEx() & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON3_DOWN_MASK)) == 0))
|| e.getID() == MouseEvent.MOUSE_EXITED) {
// 按鈕凸起來
setBorderUp();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -