commandbutton.java
来自「开源(Open Source)项目JHotDraw的文档和源程序」· Java 代码 · 共 48 行
JAVA
48 行
/*
* @(#)CommandButton.java 5.2
*
*/
package CH.ifa.draw.util;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.*;
/**
* A Command enabled button. Clicking the button executes the command.
*
* @see Command
*/
public class CommandButton
extends JButton implements ActionListener {
private Command fCommand;
/**
* Initializes the button with the given command.
* The command's name is used as the label.
*/
public CommandButton(Command command) {
super(command.name());
fCommand = command;
addActionListener(this);
}
/**
* Executes the command. If the command's name was changed
* as a result of the command the button's label is updated
* accordingly.
*/
public void actionPerformed(ActionEvent e) {
fCommand.execute();
if (!getLabel().equals(fCommand.name()) ) {
setLabel(fCommand.name());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?