添加用户信息

package cn.hucu.gui4;


import java.awt.Color;
import java.awt.GraphicsConfiguration;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class UserJFrame extends JFrame implements ActionListener {
    private JTextArea textUser;
    private JTextField textName,textNumber;
    private JRadioButton radioMan,radioFamale;
    private JComboBox comCity,comProvice;
    private JCheckBox check;
    private JButton btnAdd;
    private int number=1;
    private Object provinces[] = {"江苏省","浙江省","湖南省"};
private Object cities[][] = { {"南京市","苏州市","无锡市"},
             {"杭州市","宁波市","温州市","衢州市"},
             {"益阳市","长沙市","岳阳市","湘潭市"}
                   };
public UserJFrame(){
super("输入用户信息");
this.setBounds(100, 200, 360, 200);
this.getContentPane().setBackground(Color.cyan);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
this.setResizable(false);
this.getContentPane().setLayout(new GridLayout(1,2));
textUser=new JTextArea();
this.getContentPane().add(new JScrollPane(textUser) );
JPanel p=new JPanel();
p.setLayout(new GridLayout(6,1));
textNumber=new JTextField("1");
textNumber.setEditable(false);
p.add(textNumber);
textName=new JTextField("姓名");
p.add(textName);

JPanel pSex=new JPanel();
radioMan=new JRadioButton("男");
radioFamale=new JRadioButton("女");
radioMan.setSelected(true);
pSex.add(radioMan);
pSex.add(radioFamale);
p.add(pSex);
ButtonGroup group=new ButtonGroup();
group.add(radioMan);
group.add(radioFamale);

   comProvice=new JComboBox(provinces);
   p.add(comProvice);
   comProvice.addActionListener(this);
   comCity=new JComboBox(cities[0]);
   p.add(comCity);
   btnAdd=new JButton("添加");
   p.add(btnAdd);
   btnAdd.setActionCommand("a");
   btnAdd.addActionListener(this);
   
   this.getContentPane().add(p);
this.setVisible(true);

}







public static void main(String[] args) {
new UserJFrame();


}










@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==comProvice){
int i=comProvice.getSelectedIndex();
comCity.removeAllItems();
for(int j=0;j<cities[i].length;j++){
comCity.addItem(cities[i][j]);
}
}
if(e.getActionCommand().equals("a")){
String str=""+this.number+"、"+textName.getText()+":";
if(radioMan.isSelected()){
str+=" "+radioMan.getText();
}
if(radioFamale.isSelected()){
str+=""+radioFamale.getText();
}
str+=" "+comProvice.getSelectedItem()+" "+comCity.getSelectedItem();
textUser.append(str+"\n");
this.number++;
textNumber.setText(""+this.number);
}

}


}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值