- 浏览: 222048 次
- 性别:
- 来自: 淄博
文章分类
- 全部博客 (666)
- java (6)
- android (9)
- 架构 (0)
- android游戏 (13)
- android系统 (14)
- c++ (14)
- 数据库 (10)
- javascript (2)
- 版本控制 (1)
- webservice (1)
- linux (5)
- uml (1)
- android多媒体部分 (16)
- java中的JNI (6)
- HTML5 (5)
- CSS3 (1)
- swing (13)
- 线程并发 (9)
- 分布式 (5)
- 云计算 (1)
- 通信协议 (4)
- xml (4)
- c# (1)
- lucene (0)
- ibatis (0)
- hibernate (3)
- struts1 (3)
- struts2 (4)
- jsf (0)
- spring (5)
- spring for android (0)
- 感悟 (2)
- jpa (1)
- android gis (1)
- jbpm (0)
- java设计模式 (8)
- java web (4)
- EXT js (0)
- node JS (2)
- python (3)
- c (17)
- weblogic (0)
- opencv (1)
最新评论
/**
* 单选按钮
* @time 下午10:48:14
* @author retacn yue
* @Email zhenhuayue@sina.com
*/
public class Test_RadioButtonDemo extends JPanel {
JLabel pictute;
static String aString = "A";
static String bString = "B";
static String cString = "C";
static String dString = "D";
static String eString = "E";
private static final long serialVersionUID = 1L;
/**
* 构造器
*/
private Test_RadioButtonDemo() {
JRadioButton aButton = new JRadioButton(aString);
aButton.setMnemonic('a');
aButton.setActionCommand(aString);
aButton.setBackground(Color.pink);
JRadioButton bButton = new JRadioButton(bString);
aButton.setMnemonic('b');
aButton.setActionCommand(aString);
aButton.setBackground(Color.pink);
JRadioButton cButton = new JRadioButton(cString);
aButton.setMnemonic('c');
aButton.setActionCommand(aString);
aButton.setBackground(Color.pink);
JRadioButton dButton = new JRadioButton(dString);
aButton.setMnemonic('d');
aButton.setActionCommand(aString);
aButton.setBackground(Color.pink);
JRadioButton eButton = new JRadioButton(eString);
aButton.setMnemonic('e');
aButton.setActionCommand(aString);
aButton.setBackground(Color.pink);
// 将单选按钮放到同一组中
ButtonGroup group = new ButtonGroup();
group.add(aButton);
group.add(bButton);
group.add(cButton);
group.add(dButton);
group.add(eButton);
// 给按钮添加监听
RadioListener listener = new RadioListener();
aButton.addActionListener(listener);
bButton.addActionListener(listener);
cButton.addActionListener(listener);
dButton.addActionListener(listener);
eButton.addActionListener(listener);
// 将按钮添加到面板中
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new GridLayout(0, 1));
radioPanel.add(aButton);
radioPanel.add(bButton);
radioPanel.add(cButton);
radioPanel.add(dButton);
radioPanel.add(eButton);
// 添加图片控件
pictute = new JLabel(new ImageIcon("images/+" + aString + ".gif"));
pictute.setPreferredSize(new Dimension(200, 200));
setBackground(Color.pink);
setLayout(new BorderLayout());
add(radioPanel, BorderLayout.WEST);
add(pictute);
}
/**
*
* @time 4:49:05 PM
* @author retacn yue
* @Email zhenhuayue@sina.com
*/
class RadioListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// 更换图片
pictute.setIcon(new ImageIcon("images/" + e.getActionCommand() + ".gif"));
}
}
public static void main(String[] args) {
JFrame frame = new JFrame("Test_RadioButtonDemo");
Test_RadioButtonDemo test_RadioButtonDemo = new Test_RadioButtonDemo();
frame.setSize(300, 300);
frame.setBackground(Color.pink);
frame.setContentPane(test_RadioButtonDemo);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
发表评论
-
swing 学习笔记一(画板Panel )
2012-09-04 11:18 730/** * 画板 * * @time 3:38:10 P ... -
swing学习笔记二(画布Canvas)
2012-09-04 11:19 646/** * 画布 * @time 11:23:53 AM ... -
swing学习笔记三(菜单快捷MenuBar )
2012-09-06 22:43 692/** * 菜单快捷键 * * @time 12:40: ... -
swing学习笔记五(进度条ProgressMonitor )
2012-09-06 22:44 676/** * 进度条 * * @time 3:30:01 ... -
swing学习笔记六(对话框Dialog )
2012-09-06 22:47 672/** * 对话框 * * @time 11:09:20 ... -
swing 学习笔记七(菜单MenuBar )
2012-09-06 22:49 771/** * 菜单 * * @time 10:24:50 ... -
swing 学习笔记八(列表JList )
2012-09-08 16:32 632/** * 列表 * @time 4:53:26 PM ... -
swing 学习笔记九(选项卡 JApplet是japplet的扩展)
2012-09-08 16:33 631/** * 选项卡 JApplet是japplet的扩展 ... -
swing 学习笔记十(边界面局管理BorderLayout)
2012-09-08 16:35 545/** * 边界面局管理 * * @time 2:59: ... -
swing学习笔记十一(卡片布局管理器CardLayout )
2012-09-09 10:54 633/** * 卡片布局管理器 * * @time 9:49 ... -
swing 学习笔记十二(网格布局GridLayout)
2012-09-09 10:59 515/** * 网格布局 * * @time 3:22:44 ... -
swing学习笔记十四(复选框JCheckBox )
2012-09-09 11:00 548/** * 复选框 * * @time 3:54:18 ...
相关推荐
主要介绍了Java Swing组件单选框JRadioButton用法,结合具体实例形式分析了Swing单选框JRadioButton的使用方法及相关操作注意事项,需要的朋友可以参考下
电子文档,描述界面普通界面设计基础知识,只针度初学者,
主要介绍了Java Swing JRadioButton单选按钮具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
用java编程来实现单选按钮组件,通过使用单选按钮来实现性别选择,并创建监听器进行监听。
JRadioButton是Swing库提供的一个单选按钮组件,它允许用户从一组选项中选择一个选项。
单选按钮:JRadioButton 按钮组:ButtonGroup 组合框:JComboBox 列表:JList 文本字段:JTextField 文本区域:JTextArea 滚动条:JScrollBar 滑块:JSlider 进度栏:JProgressBar 格式化字段:JFormattedTextField ...
java JRadioButton的使用 java JRadioButton的使用 java JRadioButton的使用
一步一步地实现菜单栏(JMenuBar)工具栏(JPopupMenu)组合框(JComboBox)复选框(JCheckBox)单选按钮(JRadioButton)文本域的综合应用(三) 源程序
1. Swing1. Swing1. Swing 1. Swing1. Swing1. Swing1. Swing简介 ................................ ................................ ................................ ................................ .........
java 使用swing的样例,eclipse导入maven项目 JFrame JPanel JLabel JRadioButton JCheckBox JButton ActionListener使用小程序
了解抽象窗口工具包 (AWT)和Swing的概念及区别 ...JCheckBox、JRadioButton、JComboBox 运用以上组件进行图形界面设计 理解事件监听器 理解内部类和匿名类 理解布局管理器 BorderLayout 、FlowLayout、GridLayout
单选按钮| 复选框| 组合框 浏览图像文件并使用Java Swing在Jlabel上显示它 如何从计算机显示图像并将图像插入到JTable单元中-Java GUI-NetBeans IDE教程 如何在Java中显示从JTable单元到JLabel的图像(Java源代码) ...
1.编写程序,使单选按钮可以使用isSelected()方法判断是否被选中,用getText()方法获得按钮的文本,JRadioButton对象也可以产生ItemEvent事件,该事件的处理方法与JCheckBox的处理方法相同。 2、编写程序,使...
目录Swing 常用控件1. JFrame2. JLabel3. JButton4. JTextArea5. JTextField6. JPasswordField7. JRadioButton8. JCheckBox9. JComboBox10. JList Swing 常用控件 Swing 常用控件包括 JFrame、JLabel、JButton、...
2,设置一组单选RadioButton 先声明: ButtonGroup jButtonGroup = new ButtonGroup(); JRadioButton jRadioButton1 = new JRadioButton(); JRadioButton jRadioButton2 = new JRadioButton(); JRadioButton ...
这些字段应附有参数标签,如上所示 • 四个JRadioButton组件,用于确定将哪个运算符应用于两个输入值。 这些按钮必须组合在一起,以便一次只能选择其中一个。 您需要阅读 Java 教程以了解这是如何完成的。 •计算...
本程序包含borderlayout、flowlayout、gridbaglayout三种布局 使用ActionListener, ItemListener 2个监听 包含将结果写入文件 ...包含JTextField、JRadioButton、JComboBox、JList、JTextArea等组件的基本用法。
JRadioButton(单选按钮);组合框JComboBox;组合框JComboBox—事件;public class Test4 extends JFrame implements ActionListener { String[] items = { "篮球", "足球", "乒乓球" }; JComboBox<String> box = new ...
使用java基础知识实现的图书管理系统,数据库为mysql,界面利用 java 的swing开发
031810_【第18章:图形界面】_单选钮:JRadioButton笔记.pdf 031811_【第18章:图形界面】_复选框:JCheckBox笔记.pdf 031812_【第18章:图形界面】_列表框:JList笔记.pdf 031812_【第18章:图形界面】_下拉列表框...