- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadioButtons.java
More file actions
Latest commit
47 lines (38 loc) · 1.03 KB
/
Copy pathRadioButtons.java
File metadata and controls
47 lines (38 loc) · 1.03 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
importjava.awt.event.*;
importjavax.swing.*;
publicclassRadioButtonsimplementsActionListener
{
JRadioButtonr1,r2;
JFramenewFrame = newJFrame();
publicvoidactionPerformed(ActionEvente)
{
if( e.getSource() == r1)
JOptionPane.showMessageDialog(newFrame, "You are a male!");
if( e.getSource() == r2)
JOptionPane.showMessageDialog(newFrame, "You are a female!");
}
RadioButtons()
{
JFrameframe = newJFrame("Choose your gender");
frame.setSize(400,400);
frame.setResizable(false);
frame.setLayout(null);
r1 = newJRadioButton("Male");
r2 = newJRadioButton("Female");
r1.setBounds(90,100,100,20);
r2.setBounds(90,150,100,20);
ButtonGroupbg = newButtonGroup();
bg.add(r1);
bg.add(r2);
r1.addActionListener(this);
r2.addActionListener(this);
frame.add(r1);
frame.add(r2);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
publicstaticvoidmain(String[] args)
{
newRadioButtons();
}
}