1、按钮JButton

public class Demo extends JFrame {
public Demo() {
setBounds(100, 100, 400, 200);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new GridLayout(2, 3, 10, 10));
JButton btn[] = new JButton[6];//定义6个按钮数组
for (int i = 0; i < btn.length; i++) {
btn[i] = new JButton();//创建按钮
c.add(btn[i]);
}
btn[0].setText("不可用");
btn[0].setEnabled(false);
btn[1].setText("背景色");
btn[1].setBackground(Color.GREEN);
btn[2].setText("无边框");
btn[2].setBorderPainted(false);
btn[3].setText("有边框");
btn[3].setBorder(BorderFactory.createLineBorder(Color.RED));
setVisible(true);
Icon icon=new ImageIcon("src/logo.png");
btn[4].setIcon(icon);//给按钮设置图片
btn[4].setToolTipText("图片按钮");//鼠标悬停提示
btn[5].setText("弹出提示框");
btn[5].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(Demo.this,"这是消息提示框");
}
});
} public static void main(String[] args) {
new Demo();
}
}

2、单选按钮JRadioButton

public class Demo extends JFrame {
public Demo() {
setBounds(100, 100, 200, 100);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JRadioButton rb1 = new JRadioButton("男");
JRadioButton rb2 = new JRadioButton("女");
c.add(rb1);
c.add(rb2);
ButtonGroup group=new ButtonGroup();//按钮组,使按钮单选,而不被同时选中
group.add(rb1);
group.add(rb2);
rb1.setSelected(true);//默认选中
setVisible(true);
} public static void main(String[] args) {
new Demo();
}
}

3、复选框JCheckBox

public class Demo extends JFrame {
public Demo() {
setBounds(100, 100, 200, 100);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JCheckBox cb1=new JCheckBox("桔子");
JCheckBox cb2=new JCheckBox("苹果");
JCheckBox cb3=new JCheckBox("香蕉");
cb1.setSelected(true);//默认选中
c.add(cb1);c.add(cb2);c.add(cb3);
setVisible(true);
} public static void main(String[] args) {
new Demo();
}
}

按钮JButton,单选按钮JRadioButton,复选框JCheckBox的更多相关文章

  1. 单选按钮 JradioButton 和复选框 JcheckBox 的使用

    package first; import javax.swing.*; import java.awt.*; import java.awt.event.*; class BRTest extend ...

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

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

  3. js做全选,用一个checkbox复选框做多个checkbox复选框的全选按钮,有一个复选框未被选择时,全选按钮的checked就为false

    用一个checkbox复选框做多个checkbox复选框的全选按钮,有一个复选框未被选择时,全选按钮的checked就为false,当所有checkbox都被选中时,全选按钮也被选中. 详解: 有两种 ...

  4. 【特效】单选按钮和复选框的美化(只用css)

    表单的默认样式都是比较朴素的,实际页面中往往需要美化他们.这里先说说单选按钮和复选框,有了css3,这个问题就变的好解决了.利用input与label相关联,对label进行美化并使其覆盖掉原本的in ...

  5. UI设计规范:单选按钮 vs 复选框,没那么简单

    无论是网页设计,还是移动app设计,都经常用到单选按钮和复选框这两个组件.这两个组件看似意义明确,很好区分,但在实际设计中却很容易用错,带来不好的用户体验. 本文中我通过列举几个典型的错误用法,帮助设 ...

  6. mui开发中获取单选按钮、复选框的值

    js获取单选按钮的值 function getVals(){ var res = getRadioRes('rds'); if(res == null){mui.toast('请选择'); retur ...

  7. 20151215单选按钮列表,复选框列表:CheckBoxList

    单选框:RadioButton GroupName:组名,如果要实现单选效果每个单选按钮的组名必须一样 是否被选中 RadioButton.checked 单选按钮列表:RadioButtonList ...

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

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

  9. JQ 操作样式,单选按钮跟复选框

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. 实践简单的项目WC

    #include<iostream> #include<fstream> #include<string> #include<Windows.h> us ...

  2. Reading Task 2 —— by12061154Joy

    关于Silver Bullet: Brooks在“No Silver Bullet”主张并断言在未来的十年之内(从1986年文章发表后开始计算),不会有任何单一的软件工程上的突破,能够让程序设计的生产 ...

  3. Week3 关于“微软必应词典客户端”的案例分析

    第一部分  调研,评测 一.iphone客户端的bug挖掘: 1.在例句中点击单词或短语,如果这个时候点得稍微快了一点,关联相应的翻译时会出现混乱. 经过调查发现,这个bug应该是必应得一个全平台错误 ...

  4. [BUAA-SE-2018]结对作业测试报告

    目录 1. 测试方式 2. 评分规则 2.1 测试点组成 2.2 性能测试的分级 2.3 重新提交的扣分策略 3. 评测结果 3.1 罗老师班 3.2 任老师班 3.3 表中数据的说明 4. 测试点下 ...

  5. 《Linux内核设计与实现》第一二章笔记

    第一章 linux内核简介 每个处理器在任何时间点上的活动必然概括为下列三者: 运行于用户空间,执行用户进程 运行于内核空间,处于进程上下文,代表某个特定的进程执行 运行于内核空间,处于中断上下文,与 ...

  6. 软件工程导论课后习题Github作业(把一个英文句子中的单词次序逆序,单词中字母正常排列)

    Java源代码    package yly; import java.util.Scanner; public class ruanjian { public static void main(St ...

  7. The import * cannot be resolved

    背景 使用eclipse jee做练习的时候,下载了老师的项目源码.考虑到老师用的时myeclipse,目录结构略有不同,所有不想直接导入项目,又考虑到,可能环境不一样,会出现这样那样的问题,所以我的 ...

  8. #Leetcode# 788. Rotated Digits

    https://leetcode.com/problems/rotated-digits/ X is a good number if after rotating each digit indivi ...

  9. 无法定位程序输入点 zend_empty_string php7.dll

    phpstudy 在安装php_redis.dll php_redis.pdb 时,需要用到php_igbinary.dll扩展.但我下载的版本不对.下载的是7.2版本的. 所以报以上错误.可选择版本 ...

  10. rsync实现数据同步

    希望两台机器指定目录的数据保持一致 192.168.19.252(master)                 192.168.19.251(slave) /cache 拉复制            ...