There is something wrong with this Java program but I do not know what it is. can someone help 2 import java.awt.*; 3 import javax.swing.*; 4 import java.awt.event.*; 5 import java.awt.Color; 6 7 8 class Radiobutton extends JFrame { 9 10 11 JRadioButton jRadioButton1; 12 JRadioButton jRadioButton2; 13 JButton jButton; 14 ButtonGroup G1; 15 JLabel L1; 16 17 public Radiobutton() 18 { 19 this.setLayout(null); 20 jRadioButton1 = new JRadioButton(); 21 jRadioButton2 = new JRadioButton(); 22 jButton = new JButton("Click"); 23 G1 = new ButtonGroup(); 24 L1 = new JLabel("Qualification"); 25 26 jRadioButton1.setText("Under-Graduate"); 27 jRadioButton2.setText("Graduate"); 28 29 jRadioButton1.setBounds(120, 30, 120, 50); 30 jRadioButton2.setBounds(250, 30, 80, 50); 31 jButton.setBounds(125, 90, 80, 30); 32 L1.setBounds(20, 30, 150, 50); 33 34 this.add(jRadioButton1); 35 this.add(jRadioButton2); 36 this.add(jButton); 37 this.add(L1); 38 39 G1.add(jRadioButton1); 40 G1.add(jRadioButton2); 41 42 jButton.addActionListener(new ActionListener() { 43 44 45 public void actionPerformed(ActionEvent e) { 46 47 String qual = " "; 48 49 if (jRadioButton1.isSelected()) { 50 51 qual = "Under-Graduate"; 52 } 53 54 else if (jRadioButton2.isSelected()) { 55 56 qual = "Graduate"; 57 } 58 else { 59 60 qual = "NO Button selected"; 61 } 62 63 JOptionPane.showMessageDialog(Radiobutton.this, qual); 64 } 65 }); 66 } 67 } 68 69 class RadioButton { 70 71 public static void main(String args[]) { 72 Radiobutton f = new Radiobutton(); 73 f.setBounds(100, 100, 400, 200); 74 f.setTitle("RadioButtons"); 75 f.getContentPane().setBackground(Color.LIGHT_GRAY); 76 f.setVisible(true); 77 } 78 }
There is something wrong with this Java program but I do not know what it is. can someone help
2 import java.awt.*;
3 import javax.swing.*;
4 import java.awt.event.*;
5 import java.awt.Color;
6
7
8 class Radiobutton extends JFrame {
9
10
11 JRadioButton jRadioButton1;
12 JRadioButton jRadioButton2;
13 JButton jButton;
14 ButtonGroup G1;
15 JLabel L1;
16
17 public Radiobutton()
18 {
19 this.setLayout(null);
20 jRadioButton1 = new JRadioButton();
21 jRadioButton2 = new JRadioButton();
22 jButton = new JButton("Click");
23 G1 = new ButtonGroup();
24 L1 = new JLabel("Qualification");
25
26 jRadioButton1.setText("Under-Graduate");
27 jRadioButton2.setText("Graduate");
28
29 jRadioButton1.setBounds(120, 30, 120, 50);
30 jRadioButton2.setBounds(250, 30, 80, 50);
31 jButton.setBounds(125, 90, 80, 30);
32 L1.setBounds(20, 30, 150, 50);
33
34 this.add(jRadioButton1);
35 this.add(jRadioButton2);
36 this.add(jButton);
37 this.add(L1);
38
39 G1.add(jRadioButton1);
40 G1.add(jRadioButton2);
41
42 jButton.addActionListener(new ActionListener() {
43
44
45 public void actionPerformed(ActionEvent e) {
46
47 String qual = " ";
48
49 if (jRadioButton1.isSelected()) {
50
51 qual = "Under-Graduate";
52 }
53
54 else if (jRadioButton2.isSelected()) {
55
56 qual = "Graduate";
57 }
58 else {
59
60 qual = "NO Button selected";
61 }
62
63 JOptionPane.showMessageDialog(Radiobutton.this, qual);
64 }
65 });
66 }
67 }
68
69 class RadioButton {
70
71 public static void main(String args[]) {
72 Radiobutton f = new Radiobutton();
73 f.setBounds(100, 100, 400, 200);
74 f.setTitle("RadioButtons");
75 f.getContentPane().setBackground(Color.LIGHT_GRAY);
76 f.setVisible(true);
77 }
78 }
Trending now
This is a popular solution!
Step by step
Solved in 3 steps