-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadioButtonDemo.java
More file actions
70 lines (66 loc) · 1.82 KB
/
Copy pathRadioButtonDemo.java
File metadata and controls
70 lines (66 loc) · 1.82 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
66
67
68
69
70
package Swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class RadioButtonDemo {
public static void main(String[] args) {
new Radio();
}
}
class Radio extends JFrame{
JTextField t1;
JButton b;
JLabel l;
JRadioButton r1,r2;
JCheckBox c1,c2;
public Radio(){
t1=new JTextField(15);
r1=new JRadioButton("Male");
r2=new JRadioButton("Female");
c1=new JCheckBox("Singer");
c2=new JCheckBox("Dancer");
b=new JButton("Ok");
l=new JLabel("Greetings");
setTitle("RadioButton");
setVisible(true);
setSize(400, 400);
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(t1);
add(r1);
add(r2);
add(c1);
add(c2);
ButtonGroup grp=new ButtonGroup();
grp.add(r1);
grp.add(r2);
add(b);
add(l);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String t=t1.getText();
String msg;
if(r1.isSelected()){
msg="Namaste!! Mr. "+t;
}
else
msg="Namaste!! Mrs. "+t;
if(c1.isSelected())
msg+="The Singer";
if (c2.isSelected())
msg+=" Dancer";
l.setText(msg);
}
});
// c1.addItemListener(new ItemListener() {
// @Override
// public void itemStateChanged(ItemEvent e) {
// System.out.println(c1.getText());
// }
// });
}
}