import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class jRadioButton extends JFrame{
JRadioButton jrb1,jrb2,jrb3;
ButtonGroup bg;
public jRadioButton()
{
super("My jradiobutton");
this.setSize(400, 400);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//按钮
jrb1 = new JRadioButton("河北");
jrb1.setForeground(Color.BLUE);
this.add(jrb1);
jrb2 = new JRadioButton("上海");
jrb2.setForeground(Color.CYAN);
this.add(jrb2);
jrb3 = new JRadioButton("江苏");
jrb3.setForeground(Color.GRAY);
this.add(jrb3);
//加入到按钮组
bg= new ButtonGroup();
bg.add(jrb1);
bg.add(jrb2);
bg.add(jrb3);
//流布局
this.setLayout(new FlowLayout());
//加边框
JPanel jp = new JPanel();
jp.add(jrb1);
jp.add(jrb2);
jp.add(jrb3);
jp.setBorder(BorderFactory.createEtchedBorder());
this.getContentPane().add(jp);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new jRadioButton();
}
}
java作业——单项选择
最新推荐文章于 2023-03-17 12:59:09 发布