Me丿以卿之名

java程序员一枚-_-!

添加用户信息

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);
}

}


}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangjian_an/article/details/49893993
个人分类: 课程设计类
所属专栏: java图形用户界面
上一篇hdu acm java
下一篇毕业设计之文本编辑器
想对作者说点什么? 我来说一句

java通讯录在控制台上打印

2010年12月21日 2KB 下载

融云-用户信息提供者测试 demo

2015年12月11日 4.37MB 下载

没有更多推荐了,返回首页

关闭
关闭