博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

自考 exec 7 3

Posted on 2012-08-07 21:34  紫冰龙  阅读(139)  评论(0编辑  收藏  举报
import javax.swing.*;

import java.awt.FlowLayout;
import java.awt.event.*;
public class Exec73 extends JFrame implements ActionListener{

    /**
     * @param args
     */
    public static void main(String[] args) {
        new Exec73();

    }
    Exec73(){
        this.setTitle("Exec73 Test");
        this.setSize(400,400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        
        jrb1 = new JRadioButton("Foot Ball");
        jrb2 = new JRadioButton("Basket Ball");
        jrb3 = new JRadioButton("Swim");
        text = new JTextField(10);
        
        jrb1.addActionListener(this);
        jrb2.addActionListener(this);
        jrb3.addActionListener(this);
        
        this.setLayout(new FlowLayout());
        
        ButtonGroup g = new ButtonGroup();
        g.add(jrb1);g.add(jrb2);g.add(jrb3);
        
        add(jrb1);
        add(jrb2);
        add(jrb3);
        add(text);
        
        setVisible(true);
        pack();
        
        
    }
    public void actionPerformed(ActionEvent e) {
        JRadioButton tjrb = (JRadioButton)e.getSource();
        text.setText(tjrb.getActionCommand());
    }
    JRadioButton jrb1,jrb2,jrb3;
    JTextField text;
}