单选按钮 JradioButton 和复选框 JcheckBox 的使用
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 的使用的更多相关文章
- 按钮JButton,单选按钮JRadioButton,复选框JCheckBox
1.按钮JButton public class Demo extends JFrame { public Demo() { setBounds(100, 100, 400, 200); setDef ...
- 3.Android之单选按钮RadioGroup和复选框Checkbox学习
单选按钮和复选框在实际中经常看到,今天就简单梳理下. 首先,我们在工具中拖进单选按钮RadioGroup和复选框Checkbox,如图: xml对应的源码: <?xml version=&quo ...
- JButton 按钮,JRadioJButton单选按钮,JChectBox复选框
一. [按钮JButton] //导入Java类 import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;im ...
- Android 单选按钮(RadioButton)和复选框(CheckBox)的使用
1.RadioButton (1)介绍 (2)单选按钮点击事件的用法 (3)RadioButton与RadioGroup配合使用实现单选题功能 (4)xml布局及使用 <?xml version ...
- jquery操作radio单选按钮、checked复选框。
一.radio 取值: $('input[name=radio]:checked').val(); 二.checked 判断checked是否被选中 $("input[type='check ...
- 8、单选按钮(JRadioButton)和复选框(JCheckBox)
8.单选按钮(JRadioButton)和复选框(JCheckBox) 实现一个单选按钮(或复选框),此按钮项可被选择或取消选择,并显示其状态.JRadioButton对象与ButtonGroup对象 ...
- DOM(十)使用DOM设置单选按钮、复选框、下拉菜单
1.设置单选按钮 单选按钮在表单中即<input type="radio" />它是一组供用户选择的对象,但每次只能选一个.每一个都有checked属性,当一项选择为t ...
- [ PyQt入门教程 ] PyQt5基本控件使用:单选按钮、复选框、下拉框
本文主要介绍PyQt5界面最基本使用的单选按钮.复选框.下拉框三种控件的使用方法进行介绍. 1.RadioButton单选按钮/CheckBox复选框.需要知道如何判断单选按钮是否被选中. 2.Com ...
- android 中单选和复选框监听操作
单选按钮RadioGroup.复选框CheckBox都有OnCheckedChangeListener事件,我们一起了解一下. package com.genwoxue.oncheckedchange ...
随机推荐
- Linux复制和移动文件
cp:复制文件和目录 cp /etc/log /mu 把/etc/log复制到/mu目录下 -r:递归复制目录 -f:强制复制目录或文件 -i:交互式 -p:保留源文件或目录的属性 mv:移动或重命名 ...
- Bellman_ford标准算法
Bellman_ford求最短路可以说这个算法在某些地方和dijkstra还是有些相似的,它们的松弛操作基本还是一样的只不过dijkstra以图中每个点为松弛点对其相连接的所有边进行松弛操作 而Bel ...
- java设计模式之适配器模式以及在java中作用
适配器作用就是讲一个接口适配到另一个接口,在Java 的I/O类库中有很多这样的需求,如将字符串数据转变成字节数据保存到文件中,将字节数据转变成流数据等. 以InputStreamReader和Out ...
- swarm 服务器安装
apt install docker.io-----------------------配置加速器.私有仓库地址---------------------mkdir -p /etc/dockertee ...
- POJ 1463 Strategic game(二分图最大匹配)
Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...
- 一个python游戏源码
#finalPyPong.py import pygame,sys class MyBallClass(pygame.sprite.Sprite): def __init__(self,image_f ...
- feof问题
feof()函数是我们C语言中操作文件常见的函数,也是我们最容易出错的函数 这个函数用来表示文件指针是否已经到了文件末尾的下一个位置.这个函数是通用的 可以用在文本文件和二进制文件 (EOF是文件结束 ...
- web online ide &web online editor & web online playground & web online runtime
web online ide &web online editor web online ide &web online editor & web online playgro ...
- dnsmasq-2.48没有ipset特性,安装dnsmasq-2.71来支持ipset
iptables只能根据ip地址进行转发,不能识别域名,而dnsmasq-full不仅可以实现域名-IP的映射,还可以把这个映射关系存储在ipset中,所以使用dnsmasq+ipset就可以实现ip ...
- CCmdUI
原文链接地址:http://blog.csdn.net/luicha/article/details/6771185 CCmdUI是一个只被使用于ON_UPDATECOMMAND_UI消息的响应函数中 ...