import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JRadioButton_test extends JFrame implements ActionListener{
    JRadioButton jRadioButton1 = new JRadioButton("男");
    JRadioButton jRadioButton2 = new JRadioButton("女");
    ButtonGroup buttonGroup1 = new ButtonGroup();
    JButton jButton1=new JButton("确定");
    JTextField jTextField1=new JTextField();
    public JRadioButton_test(){
        setLayout(null);
        setTitle("单选按钮");
        jRadioButton1.setBounds(new Rectangle(20, 20, 60, 20));
        jRadioButton2.setBounds(20, 40, 51, 20);      
        jTextField1.setBounds(80,30,60,30);
        jButton1.setBounds(50,80, 80, 25);
        jButton1.addActionListener(this);       
        buttonGroup1.add(jRadioButton1);
        buttonGroup1.add(jRadioButton2);
        add(jRadioButton1);
        add(jRadioButton2);
        add(jButton1);
        add(jTextField1);
    }
    public static void main(String args[]) {
         JRadioButton_test ta = new JRadioButton_test();
         ta.setBounds(200, 300, 180, 160);
         ta.validate();
         ta.setVisible(true);
    }	
    public void actionPerformed(ActionEvent e) {
         if(jRadioButton1.isSelected())
         jTextField1.setText(jRadioButton1.getText());
         if(jRadioButton2.isSelected())
         jTextField1.setText(jRadioButton2.getText());
    }
}
