I don't even know if this code is right, I'm still new to java and have no clue if this is even right. It's meant to be 2 radio buttons and a checkbox when male checkbox is selected and checkbox C1 is selected then it opens a new class but nothing happens
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WordDocumentTest extends JFrame {
JCheckBox C1 = new JCheckBox("Safety Switch");
JRadioButton male = new JRadioButton("male");
JRadioButton female = new JRadioButton("Female");
private JPanel p1=new JPanel();
public WordDocumentTest(String s){
super(s);
Container content=getContentPane();
content.setLayout(new FlowLayout());
Font f=new Font("TimesRoman", Font.BOLD,20);
p1.setLayout(new GridLayout(1,2));
p1.add(C1);
p1.add(male);
p1.add(female);
content.add(p1);
this.add(male);
this.add(female);
JRadioButton button1 = male;
JRadioButton button2 = female;
ButtonGroup group = new ButtonGroup();
group.add(button1);
group.add(button2);
setSize(250,400); setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object target=e.getSource();
if (C1.isSelected() && male.isSelected()){
new MyFrame("");
}
}
}
Any tips or anything would help a bunch thanks
Aucun commentaire:
Enregistrer un commentaire