-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathButtonGroups.java
More file actions
62 lines (47 loc) · 1.6 KB
/
ButtonGroups.java
File metadata and controls
62 lines (47 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gui;
/**
* RUN:
* javac -cp .; gui/ButtonGroups.java && java -cp .; gui.ButtonGroups
* OUTPUT:
*
*/
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.lang.reflect.*;
import net.mindview.util.*;
public class ButtonGroups extends JFrame {
private static final int WIDTH = 500;
private static final int HEIHGT = 350;
private static String[] ids = {"June", "Ward", "Beaver", "Wally", "Eddie", "Lumpy"};
static JPanel makeBPanel(Class<? extends AbstractButton> kind, String[] ids) {
ButtonGroup bg = new ButtonGroup();
JPanel jp = new JPanel();
String title = kind.getName();
title = title.substring(title.lastIndexOf('.')+1);
jp.setBorder(new TitledBorder(title));
for (String id : ids) {
AbstractButton ab = new JButton("failed");
try {
Constructor ctor = kind.getConstructor(String.class);
ab = (AbstractButton) ctor.newInstance(id);
}
catch (Exception ex) {
System.err.println("can't create " + kind);
}
bg.add(ab);
jp.add(ab);
}
return jp;
}
public ButtonGroups() {
setLayout(new FlowLayout());
add(makeBPanel(JButton.class, ids));
add(makeBPanel(JToggleButton.class, ids));
add(makeBPanel(JCheckBox.class, ids));
add(makeBPanel(JRadioButton.class, ids));
}
public static void main(String[] args) {
SwingConsole.run(new ButtonGroups(), WIDTH, HEIHGT);
}
}