码迷,mamicode.com
首页 > 编程语言 > 详细

java Swing 之单选按钮和复选按钮的使用

时间:2014-05-03 16:54:40      阅读:350      评论:0      收藏:0      [点我收藏+]

标签:java   swing   

/**
 * java Swing 单选按钮
 * @author gao
 */
package com.gao;

import java.awt.FlowLayout;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;

public class JRadioButtonDemo extends JFrame {
	public JRadioButtonDemo(){
		this.setTitle("单选按钮的使用");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBounds(100, 100, 250, 100);
		JPanel contentPane=new JPanel();
		contentPane.setBorder(new EmptyBorder(5,5,5,5));
		this.setContentPane(contentPane);
		contentPane.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
		JRadioButton randioButton1=new JRadioButton("Java");
		JRadioButton randioButton2=new JRadioButton("PHP",true);
		JRadioButton randioButton3=new JRadioButton("C++");
		contentPane.add(randioButton1);
		contentPane.add(randioButton2);
		contentPane.add(randioButton3);
		ButtonGroup group=new ButtonGroup();
		group.add(randioButton1);
		group.add(randioButton2);
		group.add(randioButton3);
		this.setVisible(true);
		
	}
    public static void main(String[]args){
    	JRadioButtonDemo example=new JRadioButtonDemo();
    }
}

bubuko.com,布布扣


/** 
 * Java Swing 复选框
 * @author gao
 */
package com.gao;

import java.awt.FlowLayout;


import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class JCheckBoxDemo extends JFrame{
     public JCheckBoxDemo(){
    	 this.setTitle("复选按钮的使用");
 		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 		this.setBounds(100, 100, 250, 100);
 		JPanel contentPane=new JPanel();
 		contentPane.setBorder(new EmptyBorder(5,5,5,5));
 		this.setContentPane(contentPane);
 		contentPane.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
 		JCheckBox checkBox1=new JCheckBox("Java");
 		JCheckBox checkBox2=new JCheckBox("PHP",true);
 		JCheckBox checkBox3=new JCheckBox("C++");
 		contentPane.add(checkBox1);
 		contentPane.add(checkBox2);
 		contentPane.add(checkBox3);
 		this.setVisible(true);
     }
     public static void main(String[]args){
    	 JCheckBoxDemo example=new JCheckBoxDemo();
     }
}

bubuko.com,布布扣

java Swing 之单选按钮和复选按钮的使用,布布扣,bubuko.com

java Swing 之单选按钮和复选按钮的使用

标签:java   swing   

原文地址:http://blog.csdn.net/guanjungao/article/details/24873215

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!