package first;
import javax.swing.*; import java.awt.*;
import java.awt.event.*;
class BRTest extends JFrame implements ItemListener,ActionListener
{
JTextField text=new JTextField(15);///文本框,显示的是当前选中的复选或单选框中的内容
BRTest(String s)
{
setSize(300,300);
setVisible(true);
setTitle(s);
setLayout(new FlowLayout());
///添加三个复选框
JCheckBox cb1=new JCheckBox("c语言");
cb1.addItemListener(this);
add(cb1);
JCheckBox cb2=new JCheckBox("c++语言");
cb2.addItemListener(this);
add(cb2);
JCheckBox cb3=new JCheckBox("java语言");
cb3.addItemListener(this);
add(cb3);
///添加三个单选按钮
JRadioButton b1=new JRadioButton("鲜花");
b1.addActionListener(this);
add(b1);
JRadioButton b2=new JRadioButton("鼓掌");
b2.addActionListener(this);
add(b2);
JRadioButton b3=new JRadioButton("鸡蛋");
b3.addActionListener(this);
add(b3);
///定义按钮组,单选按钮只有放到按钮组中才能实现单选功能
ButtonGroup bg=new ButtonGroup();
bg.add(b1);
bg.add(b2);
bg.add(b3);
add(text);
validate();
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
text.setText(e.getActionCommand());
}
public void itemStateChanged(ItemEvent ie) {
// TODO Auto-generated method stub
JCheckBox cb=(JCheckBox)ie.getItem();
text.setText(cb.getText());
}
}
public class Test
{
public static void main(String[] args)
{
new BRTest("单选按钮和复选框示例");
}
}

单选按钮 JradioButton 和复选框 JcheckBox 的使用的更多相关文章

  1. 按钮JButton,单选按钮JRadioButton,复选框JCheckBox

    1.按钮JButton public class Demo extends JFrame { public Demo() { setBounds(100, 100, 400, 200); setDef ...

  2. 3.Android之单选按钮RadioGroup和复选框Checkbox学习

    单选按钮和复选框在实际中经常看到,今天就简单梳理下. 首先,我们在工具中拖进单选按钮RadioGroup和复选框Checkbox,如图: xml对应的源码: <?xml version=&quo ...

  3. JButton 按钮,JRadioJButton单选按钮,JChectBox复选框

    一. [按钮JButton] //导入Java类 import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;im ...

  4. Android 单选按钮(RadioButton)和复选框(CheckBox)的使用

    1.RadioButton (1)介绍 (2)单选按钮点击事件的用法 (3)RadioButton与RadioGroup配合使用实现单选题功能 (4)xml布局及使用 <?xml version ...

  5. jquery操作radio单选按钮、checked复选框。

    一.radio 取值: $('input[name=radio]:checked').val(); 二.checked 判断checked是否被选中 $("input[type='check ...

  6. 8、单选按钮(JRadioButton)和复选框(JCheckBox)

    8.单选按钮(JRadioButton)和复选框(JCheckBox) 实现一个单选按钮(或复选框),此按钮项可被选择或取消选择,并显示其状态.JRadioButton对象与ButtonGroup对象 ...

  7. DOM(十)使用DOM设置单选按钮、复选框、下拉菜单

    1.设置单选按钮 单选按钮在表单中即<input type="radio" />它是一组供用户选择的对象,但每次只能选一个.每一个都有checked属性,当一项选择为t ...

  8. [ PyQt入门教程 ] PyQt5基本控件使用:单选按钮、复选框、下拉框

    本文主要介绍PyQt5界面最基本使用的单选按钮.复选框.下拉框三种控件的使用方法进行介绍. 1.RadioButton单选按钮/CheckBox复选框.需要知道如何判断单选按钮是否被选中. 2.Com ...

  9. android 中单选和复选框监听操作

    单选按钮RadioGroup.复选框CheckBox都有OnCheckedChangeListener事件,我们一起了解一下. package com.genwoxue.oncheckedchange ...

随机推荐

  1. 近期准备发布我的asp.net框架

    此框架为超轻量级架构,适合做中小型的b/s项目

  2. log报错: Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.

    报错: 解决方式: 1.登录数据库查看错误原因 结果发现账号无法正常登录出现账号被锁定的错误. 2.如何账号解锁? 用sys系统管理员账号登录数据库 SQL> alter user 用户名 ac ...

  3. Qt 绘制汽车仪表 指针旋转锯齿问题

    在前面几篇中出现的问题 http://blog.csdn.net/z609932088/article/details/53946245 这个是在QWidget下绘制的,出现了指针有锯齿的问题 后面开 ...

  4. laravel跨域问题

    // 只有同源策略才允许发送cookies // header('Access-Control-Allow-Credentials:true'); 需要要index.php下开启 最近写登录图形验证码 ...

  5. 小旭讲解 LeetCode 53. Maximum Subarray 动态规划 分治策略

    原题 Given an integer array nums, find the contiguous subarray (containing at least one number) which ...

  6. git instaweb 500 error

    在arch 系统中安装perl-cgi包. 在deiban中参考:https://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A ...

  7. 关闭电脑自带键盘(copy)

    用管理员身份运行cmd: 禁用笔记本键盘 sc config i8042prt start= disabled 启用笔记本键盘 sc config i8042prt start= auto

  8. [Java] 文件上传下载项目(详细注释)

    先上代码,最上方注释是文件名称(运行时要用到) FTServer.java /* FTServer.java */ import java.util.*; import java.io.*; publ ...

  9. 配置apache反向代理进行跨域

    配置apache反向代理 打开配置文件httpd.conf 开启 proxy_http_module 和 proxy_module 模块,将#号删除 #LoadModule proxy_module ...

  10. 洛谷 P1251 餐巾计划问题

    题目链接 最小费用最大流. 每天拆成两个点,早上和晚上: 晚上可以获得\(r_i\)条脏毛巾,从源点连一条容量为\(r_i\),费用为0的边. 早上要供应\(r_i\)条毛巾,连向汇点一条容量为\(r ...