下面列出了怎么用java.awt.Checkbox的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
/**
* Run a demonstration.
*
* @param args ignored.
*
* @throws Exception when an error occurs.
*/
public static void main(final String[] args) throws Exception {
final Frame frame = new Frame();
final Panel panel = new Panel();
panel.setLayout(new RadialLayout());
panel.add(new Checkbox("One"));
panel.add(new Checkbox("Two"));
panel.add(new Checkbox("Three"));
panel.add(new Checkbox("Four"));
panel.add(new Checkbox("Five"));
panel.add(new Checkbox("One"));
panel.add(new Checkbox("Two"));
panel.add(new Checkbox("Three"));
panel.add(new Checkbox("Four"));
panel.add(new Checkbox("Five"));
frame.add(panel);
frame.setSize(300, 500);
frame.setVisible(true);
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
public boolean getExportOptions(boolean dataSelected, boolean taxaSelected){
MesquiteInteger buttonPressed = new MesquiteInteger(1);
PhylipExporterDialog exportDialog = new PhylipExporterDialog(this,containerOfModule(), "Export Phylip Options", buttonPressed);
Checkbox excludedCharactersCheckbox = exportDialog.addCheckBox("export excluded characters", localWriteExcludedChars);
Checkbox exportTreesCheckbox = exportDialog.addCheckBox("export trees if present", exportTrees);
Checkbox exportRAxMLModelFileCheckbox = exportDialog.addCheckBox("save RAxML model file", exportRAxMLModelFile);
Checkbox useTranslationTableCheckbox = exportDialog.addCheckBox("use simple taxon names (for RAxML)", useTranslationTable);
exportDialog.completeAndShowDialog(dataSelected, taxaSelected);
boolean ok = (exportDialog.query(dataSelected, taxaSelected)==0);
if (ok) {
localWriteExcludedChars = excludedCharactersCheckbox.getState();
exportTrees = exportTreesCheckbox.getState();
exportRAxMLModelFile = exportRAxMLModelFileCheckbox.getState();
useTranslationTable = useTranslationTableCheckbox.getState();
userSpecifiedWriteExcludedChars = true;
taxonNameLength = exportDialog.getTaxonNamesLength();
}
exportDialog.dispose();
return ok;
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
this.target = target;
setLayout(new FlowLayout());
setBackground(Color.lightGray);
target.setForeground(Color.red);
CheckboxGroup group = new CheckboxGroup();
Checkbox b;
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.red);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.green);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.blue);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.pink);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.orange);
add(b = new Checkbox(null, group, true));
b.addItemListener(this);
b.setForeground(Color.black);
target.setForeground(b.getForeground());
Choice shapes = new Choice();
shapes.addItemListener(this);
shapes.addItem("Lines");
shapes.addItem("Points");
shapes.setBackground(Color.lightGray);
add(shapes);
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component) e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} else if (choice.equals("Points")) {
target.setDrawMode(DrawPanel.POINTS);
}
}
}
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
this.target = target;
setLayout(new FlowLayout());
setBackground(Color.lightGray);
target.setForeground(Color.red);
CheckboxGroup group = new CheckboxGroup();
Checkbox b;
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.red);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.green);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.blue);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.pink);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.orange);
add(b = new Checkbox(null, group, true));
b.addItemListener(this);
b.setForeground(Color.black);
target.setForeground(b.getForeground());
Choice shapes = new Choice();
shapes.addItemListener(this);
shapes.addItem("Lines");
shapes.addItem("Points");
shapes.setBackground(Color.lightGray);
add(shapes);
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component) e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} else if (choice.equals("Points")) {
target.setDrawMode(DrawPanel.POINTS);
}
}
}
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
this.target = target;
setLayout(new FlowLayout());
setBackground(Color.lightGray);
target.setForeground(Color.red);
CheckboxGroup group = new CheckboxGroup();
Checkbox b;
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.red);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.green);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.blue);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.pink);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.orange);
add(b = new Checkbox(null, group, true));
b.addItemListener(this);
b.setForeground(Color.black);
target.setForeground(b.getForeground());
Choice shapes = new Choice();
shapes.addItemListener(this);
shapes.addItem("Lines");
shapes.addItem("Points");
shapes.setBackground(Color.lightGray);
add(shapes);
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component) e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} else if (choice.equals("Points")) {
target.setDrawMode(DrawPanel.POINTS);
}
}
}
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
this.target = target;
setLayout(new FlowLayout());
setBackground(Color.lightGray);
target.setForeground(Color.red);
CheckboxGroup group = new CheckboxGroup();
Checkbox b;
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.red);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.green);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.blue);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.pink);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.orange);
add(b = new Checkbox(null, group, true));
b.addItemListener(this);
b.setForeground(Color.black);
target.setForeground(b.getForeground());
Choice shapes = new Choice();
shapes.addItemListener(this);
shapes.addItem("Lines");
shapes.addItem("Points");
shapes.setBackground(Color.lightGray);
add(shapes);
}
public static final void addInverseEnablerListener(/* final GenericDialog gd, */final Checkbox master, final Component[] enable, final Component[] disable)
{
master.addItemListener(new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent ie)
{
if (ie.getStateChange() == ItemEvent.SELECTED)
{
process(enable, false);
process(disable, true);
}
else
{
process(enable, true);
process(disable, false);
}
}
private void process(final Component[] c, final boolean state)
{
if (null == c) return;
for (int i = 0; i < c.length; i++)
{
c[i].setEnabled(state);
// c[i].setVisible(state);
}
// gd.pack();
}
});
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component) e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} else if (choice.equals("Points")) {
target.setDrawMode(DrawPanel.POINTS);
}
}
}
/** @return Propertydescriptors */
@Override
protected PropertyDescriptor[] createPDs() throws IntrospectionException {
return new PropertyDescriptor[] {
new PropertyDescriptor("state", Checkbox.class), // NOI18N
new PropertyDescriptor("label", Checkbox.class), // NOI18N
new PropertyDescriptor("checkboxGroup", Checkbox.class), // NOI18N
new PropertyDescriptor("selectedObjects", Checkbox.class, "getSelectedObjects", null), // NOI18N
};
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component) e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} else if (choice.equals("Points")) {
target.setDrawMode(DrawPanel.POINTS);
}
}
}
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
this.target = target;
setLayout(new FlowLayout());
setBackground(Color.lightGray);
target.setForeground(Color.red);
CheckboxGroup group = new CheckboxGroup();
Checkbox b;
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.red);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.green);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.blue);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.pink);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.orange);
add(b = new Checkbox(null, group, true));
b.addItemListener(this);
b.setForeground(Color.black);
target.setForeground(b.getForeground());
Choice shapes = new Choice();
shapes.addItemListener(this);
shapes.addItem("Lines");
shapes.addItem("Points");
shapes.setBackground(Color.lightGray);
add(shapes);
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component) e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} else if (choice.equals("Points")) {
target.setDrawMode(DrawPanel.POINTS);
}
}
}
/**
* Returns information about component.
*/
@Override
public Hashtable<String, Object> getDump() {
Hashtable<String, Object> result = super.getDump();
result.put(TEXT_DPROP, ((Checkbox) getSource()).getLabel());
return result;
}
/**
* Maps {@code Checkbox.addItemListener(ItemListener)} through queue
*/
public void addItemListener(final ItemListener itemListener) {
runMapping(new MapVoidAction("addItemListener") {
@Override
public void map() {
((Checkbox) getSource()).addItemListener(itemListener);
}
});
}
/**
* Maps {@code Checkbox.getCheckboxGroup()} through queue
*/
public CheckboxGroup getCheckboxGroup() {
return (runMapping(new MapAction<CheckboxGroup>("getCheckboxGroup") {
@Override
public CheckboxGroup map() {
return ((Checkbox) getSource()).getCheckboxGroup();
}
}));
}
/**
* Maps {@code Checkbox.getLabel()} through queue
*/
public String getLabel() {
return (runMapping(new MapAction<String>("getLabel") {
@Override
public String map() {
return ((Checkbox) getSource()).getLabel();
}
}));
}
/**
* Maps {@code Checkbox.getState()} through queue
*/
public boolean getState() {
return (runMapping(new MapBooleanAction("getState") {
@Override
public boolean map() {
return ((Checkbox) getSource()).getState();
}
}));
}
/**
* Maps {@code Checkbox.removeItemListener(ItemListener)} through queue
*/
public void removeItemListener(final ItemListener itemListener) {
runMapping(new MapVoidAction("removeItemListener") {
@Override
public void map() {
((Checkbox) getSource()).removeItemListener(itemListener);
}
});
}
/**
* Maps {@code Checkbox.setLabel(String)} through queue
*/
public void setLabel(final String string) {
runMapping(new MapVoidAction("setLabel") {
@Override
public void map() {
((Checkbox) getSource()).setLabel(string);
}
});
}