正文

单选按钮2007-12-20 08:38:00

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

分享到:

最基本的单选按钮使用,见笑了。

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Check extends JFrame implements ActionListener
{JRadioButton c1,c2;ButtonGroup b;
 public static void main(String args[])
 {new Check();
 }
 public Check()
 {super("单选按钮");
  addWindowListener(new WindowAdapter()
  {public void windowClosing(WindowEvent e)
   {System.exit(0);
   }
  });
  b=new ButtonGroup();
  c1=new JRadioButton("启用",true);
  c2=new JRadioButton("禁用",false);
  b.add(c1);b.add(c2);
  c1.setEnabled(false);
  setLayout(null);add(c1);add(c2);
  c1.setBounds(60,140,60,20);c2.setBounds(180,140,60,20);
  c1.addActionListener(this);
  c2.addActionListener(this);
  setVisible(true);
  setSize(300,240);
 }
 public void actionPerformed(ActionEvent e)
 {if(e.getSource()==c2)
  {setTitle("启用第二个单选按钮");
   c1.setEnabled(true);c2.setEnabled(false);
  }
  else
  {setTitle("启用第一个单选的按钮");
   c1.setEnabled(false);c2.setEnabled(true);
  }
 }
}

阅读(2773) | 评论(0)


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

评论

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