?? abstractgroupbutton.java
字號:
/*
$Author: $
$Date: $
$Revision: $
$NoKeywords: $
*/
package jp.co.ntl.awt;
import java.awt.event.*;
import java.awt.*;
public abstract class AbstractGroupButton extends Component implements MouseListener, MouseMotionListener {
private ButtonGroup group;
private Checker checker;
private String actionCommand;
protected boolean pushed = false;
protected boolean toggle = true;
private transient ActionListener actionListener;
public AbstractGroupButton() {
this(null);
}
public AbstractGroupButton(ButtonGroup group) {
this(group, null);
}
public AbstractGroupButton(ButtonGroup group, Checker checker) {
this.group = group;
this.checker = checker;
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) {
if (checker != null && !checker.check(this)) {
return;
}
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())) {
if (checker != null && !checker.check(this)) {
return;
}
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 + -