/** |
* 功能: 复选框JCheckBox,单选框JRadioButton的简单使用 |
*/ |
package com.jiemian; |
import java.awt.*; |
import javax.swing.*; |
public class Text6 extends JFrame{ |
|
JPanel jp1,jp2,jp3; |
JLabel jl1,jl2; |
JCheckBox jcb1,jcb2,jcb3; |
JRadioButton jrb1,jrb2; |
JButton jb1,jb2; |
ButtonGroup bg; |
public static void main(String[] args) { |
|
Text6 text6= new Text6(); |
} |
|
public Text6(){ |
|
//创建组件 |
jp1= new JPanel(); |
jp2= new JPanel(); |
jp3= new JPanel(); |
|
jl1= new JLabel( "你喜欢的运动" ); |
jl2= new JLabel( "你的性别" ); |
|
jcb1= new JCheckBox( "足球" ); |
jcb2= new JCheckBox( "篮球" ); |
jcb3= new JCheckBox( "兵乓球" ); |
|
jrb1= new JRadioButton( "男" ); |
jrb2= new JRadioButton( "女" ); |
|
jb1= new JButton( "注册用户" ); |
jb2= new JButton( "取消注册" ); |
|
bg= new ButtonGroup(); |
bg.add(jrb1); |
bg.add(jrb2); |
|
//设置布局管理器 |
this .setLayout( new GridLayout( 3 , 1 )); |
|
//添加组件 |
jp1.add(jl1); |
jp1.add(jcb1); |
jp1.add(jcb2); |
jp1.add(jcb3); |
|
jp2.add(jl2); |
jp2.add(jrb1); |
jp2.add(jrb2); |
|
jp3.add(jb1); |
jp3.add(jb2); |
|
this .add(jp1); |
this .add(jp2); |
this .add(jp3); |
|
//对窗体进行设置 |
this .setSize( 300 , 200 ); |
this .setLocation( 300 , 300 ); |
this .setTitle( "用户注册界面" ); |
this .setIconImage(( new ImageIcon( "images\\head_boy.jpg" )).getImage()); |
this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
this .setVisible( true ); |
} |
} |