-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadioExample.java
More file actions
35 lines (35 loc) · 892 Bytes
/
RadioExample.java
File metadata and controls
35 lines (35 loc) · 892 Bytes
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
import javax.swing.*;
import java.awt.event.*;
class RadioExample extends JFrame implements ActionListener{
JRadioButton rb1,rb2;
JButton b;
RadioExample(){
rb1=new JRadioButton("Male");
rb1.setBounds(100,50,100,30);
rb2=new JRadioButton("Female");
rb2.setBounds(100,100,100,30);
ButtonGroup bg=new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
b=new JButton("click");
b.setBounds(100,150,80,30);
b.addActionListener(this);
add(rb1);
add(rb2);
add(b);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(rb1.isSelected()){ // determine the button state
JOptionPane.showMessageDialog(this,"You are male");
}
if(rb2.isSelected()){
JOptionPane.showMessageDialog(this,"You are female");
}
}
public static void main(String args[]){
new RadioExample();
}
}