2015-04-20 15:36:01 -07:00
|
|
|
//: gui/RadioButtons.java
|
|
|
|
// Using JRadioButtons.
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.*;
|
|
|
|
import static net.mindview.util.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);
|
2015-05-06 12:09:38 -07:00
|
|
|
private ActionListener al = e ->
|
2015-05-05 14:05:39 -07:00
|
|
|
t.setText("Radio button " +
|
|
|
|
((JRadioButton)e.getSource()).getText());
|
2015-04-20 15:36:01 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
} ///:~
|