正文

JRadioButton用法2005-09-18 17:22:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/hurongliang/4943.html

分享到:

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();
 }
}

阅读(5041) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册