ButtonGroupspublic class ButtonGroups extends JPanel
Fields Summary |
---|
static String[] | ids |
Constructors Summary |
---|
public ButtonGroups()
add(makeBPanel(JButton.class, ids));
add(makeBPanel(JToggleButton.class, ids));
add(makeBPanel(JCheckBox.class, ids));
add(makeBPanel(JRadioButton.class, ids));
|
Methods Summary |
---|
public static void | main(java.lang.String[] args)
Show.inFrame(new ButtonGroups(), 500, 300);
| static JPanel | makeBPanel(java.lang.Class bClass, java.lang.String[] ids)
ButtonGroup bg = new ButtonGroup();
JPanel jp = new JPanel();
String title = bClass.getName();
title = title.substring(
title.lastIndexOf('.") + 1);
jp.setBorder(new TitledBorder(title));
for(int i = 0; i < ids.length; i++) {
AbstractButton ab = new JButton("failed");
try {
// Get the dynamic constructor method
// that takes a String argument:
Constructor ctor = bClass.getConstructor(
new Class[] { String.class });
// Create a new object:
ab = (AbstractButton)ctor.newInstance(
new Object[]{ids[i]});
} catch(Exception ex) {
System.out.println("can't create " +
bClass);
}
bg.add(ab);
jp.add(ab);
}
return jp;
|
|