1个回答
推荐于2017-12-16
展开全部
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class aaa
{
/**
* @param args
*/
public static void main(String[] args)
{
TextFrame frame = new TextFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class TextFrame extends JFrame
{
public TextFrame()
{
setTitle("考试题目");
setBounds(300,300,200,120);
TextPanel panel = new TextPanel();
add(panel);
}
}
class TextPanel extends JPanel
{
private JRadioButton r1,r2;
public TextPanel()
{
//实例化单选按钮
r1 = new JRadioButton("男");
r2 = new JRadioButton("女");
JPanel p = new JPanel();
p.setBorder(BorderFactory.createTitledBorder("请选择性别"));
p.add(r1);
p.add(r2);
ButtonGroup bg = new ButtonGroup();
//将需要划分为一组的单选按钮对象添加到按钮组(注意只是逻辑上添加 和界面没有关系)
bg.add(r1);
bg.add(r2);
add(p);
}
}
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class aaa
{
/**
* @param args
*/
public static void main(String[] args)
{
TextFrame frame = new TextFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class TextFrame extends JFrame
{
public TextFrame()
{
setTitle("考试题目");
setBounds(300,300,200,120);
TextPanel panel = new TextPanel();
add(panel);
}
}
class TextPanel extends JPanel
{
private JRadioButton r1,r2;
public TextPanel()
{
//实例化单选按钮
r1 = new JRadioButton("男");
r2 = new JRadioButton("女");
JPanel p = new JPanel();
p.setBorder(BorderFactory.createTitledBorder("请选择性别"));
p.add(r1);
p.add(r2);
ButtonGroup bg = new ButtonGroup();
//将需要划分为一组的单选按钮对象添加到按钮组(注意只是逻辑上添加 和界面没有关系)
bg.add(r1);
bg.add(r2);
add(p);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |