-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRadioButtons.java
More file actions
59 lines (43 loc) · 1.32 KB
/
RadioButtons.java
File metadata and controls
59 lines (43 loc) · 1.32 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
package gui;
/**
* RUN:
* javac -cp .; gui/RadioButtons.java && java -cp .; gui.RadioButtons
* OUTPUT:
*
*/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import net.mindview.util.*;
public class RadioButtons extends JFrame {
private static final int WIDTH = 200;
private static final int HEIHGT = 125;
private JTextField t = new JTextField(15);
private ButtonGroup g = new ButtonGroup();
private JRadioButton rb1 = new JRadioButton("one", false);
private JRadioButton rb2 = new JRadioButton("two", false);
private JRadioButton rb3 = new JRadioButton("three", false);
private ActionListener al = new ActionListener(){
public void actionPerformed(ActionEvent e) {
t.setText("Radio button " + ((JRadioButton)e.getSource()).getText());
}
};
public RadioButtons() {
rb1.addActionListener(al);
rb2.addActionListener(al);
rb3.addActionListener(al);
g.add(rb1);
g.add(rb2);
g.add(rb3);
t.setEditable(false);
setLayout(new FlowLayout());
add(t);
add(rb1);
add(rb2);
add(rb3);
}
public static void main(String[] args) {
SwingConsole.run(new RadioButtons(), WIDTH, HEIHGT);
}
}