import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.FlowLayout;
public class JRadioButtonDemo
{
public static void main(String[] args)
{
JRadioButton red, white, cyan;
red = new JRadioButton ("red");
white = new JRadioButton ("white");
cyan = new JRadioButton ("cyan");
ButtonGroup group = new ButtonGroup ();
group.add (red);
group.add (white);
group.add (cyan);
JPanel panel = new JPanel (new FlowLayout (FlowLayout.CENTER, 1, 0));
panel.setBackground (Color.white);
panel.setPreferredSize (new Dimension (200,50));
panel.add (red);
panel.add (white);
panel.add (cyan);
JFrame frame = new JFrame("JRadioButtonDemo");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setContentPane(panel);
frame.pack();
frame.show();
}
}
评论