import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Userlogon extends JFrame implements ActionListener {
JRadioButton man,woman;
JPanel p1,p2,p3,p4,p5,p6;
JLabel user,password,sex,aihao,address,text;
JTextField users;
JPasswordField psw;
JButton zhuce;
JCheckBox sports,music,books;
JList list;
JComboBox jiguan;
public Userlogon(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
user=new JLabel("用户名:");
users=new JTextField(10);
p1=new JPanel();
p1.add(user);
p1.add(users);
getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,2,2));
password=new JLabel("密码:");
psw=new JPasswordField(10);
p2=new JPanel();
p2.add(password);
p2.add(psw);
sex=new JLabel("性别:");
man=new JRadioButton("男",true);
woman=new JRadioButton("女");
p3=new JPanel();
p3.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
p3.add(sex);
p3.add(man);
p3.add(woman);
getContentPane().add(p1);
getContentPane().add(p2);
getContentPane().add(p3);
ButtonGroup bg=new ButtonGroup();
bg.add(man);
bg.add(woman);
aihao=new JLabel("爱好:");
p4=new JPanel();
p4.setLayout(new FlowLayout(FlowLayout.CENTER,15,15));
sports=new JCheckBox("体育",null,true);
music=new JCheckBox("音乐");
books=new JCheckBox("读书");
p4.add(aihao);
p4.add(sports);
p4.add(music);
p4.add(books);
getContentPane().add(p4);
address=new JLabel("籍贯:");
p5=new JPanel();
jiguan=new JComboBox();
jiguan.addItem("北京");
jiguan.addItem("大连");
jiguan.addItem("上海");
p5.add(address);
p5.add(jiguan);
getContentPane().add(p5);
p6=new JPanel();
text=new JLabel();
zhuce=new JButton("注册");
p6.setLayout(new FlowLayout(FlowLayout.CENTER,60,60));
p6.add(zhuce);
p6.add(text);
getContentPane().add(p6);
zhuce.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
String s="你注册的信息是:"+"用户名:"+users.getText()+"密码:"+psw.getText()+"籍贯:"+(String)jiguan.getSelectedItem()+"性别:";
text.setText(s);
}
public static void main(String[] args){
Userlogon ui=new Userlogon();
//ui.pack();
ui.setSize(400,300);
ui.setVisible(true);
}
}
初学请多指教,这是我写的一段程序,还有没有更好的方法,请赐教,谢谢各位。