?? groupbutton.java
字號:
package jp.co.ntl.swing.ext;
import java.awt.event.*;
import java.awt.*;
import javax.swing.JComponent;
public abstract class GroupButton extends JComponent implements MouseListener, MouseMotionListener {
private ButtonGroup group;
private String actionCommand;
protected boolean pushed = false;
protected boolean toggle = true;
private transient ActionListener actionListener;
public GroupButton() {
this(null);
}
public GroupButton(ButtonGroup group) {
this.group = group;
if (group != null) {
group.add(this);
}
addMouseListener(this);
addMouseMotionListener(this);
}
public void setPushed(boolean pushed) {
this.pushed = pushed;
repaint();
}
public boolean getPushed() {
return pushed;
}
public void setToggle(boolean toggle) {
this.toggle = toggle;
repaint();
}
public boolean getToggle() {
return toggle;
}
public void setActionCommand(String command) {
actionCommand = command;
}
public String getActionCommand() {
return actionCommand;
}
public synchronized void addActionListener(ActionListener l) {
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.add(actionListener, l);
}
public synchronized void removeActionListener(ActionListener l) {
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.remove(actionListener, l);
}
protected void processEvent(AWTEvent e) {
if (e instanceof ActionEvent) {
processActionEvent((ActionEvent)e);
return;
}
super.processEvent(e);
}
protected void processActionEvent(ActionEvent e) {
if (actionListener != null) {
actionListener.actionPerformed(e);
}
}
public void mousePressed(MouseEvent me) {
if (!isEnabled()) {
return;
}
if (group != null && pushed) {
return;
}
if (toggle) {
pushed = !pushed;
processEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getActionCommand()));
} else {
pushed = true;
}
requestFocus();
repaint();
}
public void mouseReleased(MouseEvent me) {
if (!isEnabled()) {
return;
}
if (!toggle && pushed && contains(me.getPoint())) {
pushed = false;
repaint();
processEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getActionCommand()));
}
}
public void mouseClicked(MouseEvent me) {
if (!isEnabled()) {
return;
}
}
public void mouseEntered(MouseEvent me) {
if (!isEnabled()) {
return;
}
}
public void mouseExited(MouseEvent me) {
if (!isEnabled()) {
return;
}
}
public void mouseMoved(MouseEvent me) {
}
public void mouseDragged(MouseEvent me) {
if (!toggle && pushed && !contains(me.getPoint())) {
pushed = false;
repaint();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -