您的位置:首页 > 其它

SWING组件学习5:单选按钮

2007-09-18 12:23 441 查看
//单选按钮类JRadioButton
package jradiobutton;
import javax.swing.*;
public class TestRedioButton extends JFrame {
 JRadioButton r1 = new JRadioButton("南京",true);
 JRadioButton r2 = new JRadioButton("北京",false);
 JRadioButton r3 = new JRadioButton("上海",false);
 TestRedioButton(){
  super("选择喜欢的城市,只能一个呀!");
  this.setSize(100,300);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  ButtonGroup b = new ButtonGroup();
  b.add(r1);
  b.add(r2);
  b.add(r3);
  JPanel p = new JPanel();
  p.add(r1);
  p.add(r2);
  p.add(r3);
  this.setContentPane(p);
 }
 public static void main(String[] args) {
  TestRedioButton t = new TestRedioButton();
  t.show();
 }
}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  swing import string class