java如何用Jradiobutton做一个有选项的button组,然后获取选定的选项是哪个?
展开全部
//声名两单选按钮
private JRadioButton male;
private JRadioButton female;
//初始化按钮男默认选
male = new JRadioButton("男", true);
female = new JRadioButton("女");
//两按钮放同组
ButtonGroup group = new ButtonGroup();
group.add(male);
group.add(female);
//actionPerformed(...)获得按钮选择值
DefaultButtonModel model = (DefaultButtonModel) male.getModel();
if (model.getGroup().isSelected(model))
//男被选处理
else
//女被选处理
private JRadioButton male;
private JRadioButton female;
//初始化按钮男默认选
male = new JRadioButton("男", true);
female = new JRadioButton("女");
//两按钮放同组
ButtonGroup group = new ButtonGroup();
group.add(male);
group.add(female);
//actionPerformed(...)获得按钮选择值
DefaultButtonModel model = (DefaultButtonModel) male.getModel();
if (model.getGroup().isSelected(model))
//男被选处理
else
//女被选处理
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询