-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRadioButtons.java
More file actions
65 lines (51 loc) · 1.61 KB
/
Copy pathRadioButtons.java
File metadata and controls
65 lines (51 loc) · 1.61 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
63
64
65
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class RadioButtons {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JRadioButton korBtn = new JRadioButton("Korean");
JRadioButton engBtn = new JRadioButton("English");
JRadioButton chiBtn = new JRadioButton("Chinese");
ButtonGroup group = new ButtonGroup();
korBtn.setActionCommand("kor");
engBtn.setActionCommand("eng");
chiBtn.setActionCommand("chi");
group.add(korBtn);
group.add(engBtn);
group.add(chiBtn);
Font font = new Font("Arial", Font.BOLD, 24);
korBtn.setFont(font);
engBtn.setFont(font);
chiBtn.setFont(font);
engBtn.setSelected(true);
korBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println(group.getSelection().getActionCommand());
}
});
engBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println(group.getSelection().getActionCommand());
}
});
chiBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println(group.getSelection().getActionCommand());
}
});
panel.add(korBtn);
panel.add(engBtn);
panel.add(chiBtn);
frame.add(panel);
frame.setVisible(true);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}