import javax.swing.*;
import java.awt.*;
public class RadioButtonTest extends JFrame {
private JTextField jtfAnswer = new JTextField(10);
private JRadioButton jrbMale = new JRadioButton("Male");
private JRadioButton jrbFemale = new JRadioButton("Female");
private JButton jbSubmit = new JButton("Submit");
public RadioButtonTest(){
setLayout(new GridLayout(5,1));
ButtonGroup group = new ButtonGroup();
group.add(jrbMale);
group.add(jrbFemale);
add(new Label("Select gender:"));
add(jrbMale);
add(jrbFemale);
add(jtfAnswer);
add(jbSubmit);
setTitle("Radio Button");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(200, 200);
setSize(150, 150);
setVisible(true);
}
public static void main(String[] args) {
new RadioButtonTest();
}
}
我知道应该添加一个actionlistener
来获取选定的值,但是我应该在其中编码的内容是actionlistener
什么?