-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadioWithListener.java
47 lines (30 loc) · 1.03 KB
/
RadioWithListener.java
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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RadioWithListener extends JFrame implements ActionListener {
JRadioButton r1 , r2; JButton button;
RadioWithListener(){
r1 = new JRadioButton("1) Male");
r1.setBounds(30,50,120,40);
r2 = new JRadioButton("2) Female",false);
r2.setBounds(30,100,120,40);
button = new JButton("Click me");
button.setBounds(85,150,100,35);
button.addActionListener(this);
add(r1);add(r2);add(button);
setLayout(null);
setSize(400,400);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if (r1.isSelected()){
JOptionPane.showMessageDialog(this,"You are a boy");
}
if (r2.isSelected()){
JOptionPane.showMessageDialog(this,"You are Female");
}
}
public static void main(String[] args) {
new RadioWithListener();
}
}