forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadioButtons.java
More file actions
36 lines (35 loc) · 1.07 KB
/
Copy pathRadioButtons.java
File metadata and controls
36 lines (35 loc) · 1.07 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
// ui/RadioButtons.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Using JRadioButtons
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import static onjava.SwingConsole.*;
public class RadioButtons extends JFrame {
private JTextField t = new JTextField(15);
private ButtonGroup g = new ButtonGroup();
private JRadioButton
rb1 = new JRadioButton("one", false),
rb2 = new JRadioButton("two", false),
rb3 = new JRadioButton("three", false);
private ActionListener al = 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) {
run(new RadioButtons(), 200, 125);
}
}