简单通迅录不能用?
用eclipse开发的程序,运行时没错误,但点击按钮时就出错了!请各位帮帮忙错在哪了?为什么错了?谢谢(代码直接复制就可运行)import java.awt.Frame;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.lang.*;
public class userframe extends JFrame implements ActionListener, ItemListener{
int nunber=1;
JComboBox jcb_city,jcb_pr;
JTextArea ta;
JTextField tx_number,tx_name;
ButtonGroup bg;
JRadioButton rb1,rb2;
public userframe(){
super("输入用户信息");
this.setSize(400,360);
this.setLocation(100,50);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(1,2));
ta=new JTextArea();
ta.setEditable(false);
this.add(ta);
Panel pan=new Panel();
pan.setLayout(new GridLayout(6,1));
this.add(pan);
tx_number=new JTextField("1");
tx_number.setEditable(false);
pan.add(tx_number);
tx_name=new JTextField("姓名");
pan.add(tx_name);
JPanel panmi=new JPanel();
panmi.setLayout(new GridLayout(1,2));
pan.add(panmi);
bg=new ButtonGroup();
JRadioButton rb1=new JRadioButton("男",true);
bg.add(rb1);
panmi.add(rb1);
JRadioButton rb2=new JRadioButton("女",false);
bg.add(rb2);
panmi.add(rb2);
Object province[]={"浙江","江苏","湖南"};
JComboBox jcb_pr=new JComboBox(province);
jcb_pr.addItemListener(this);
pan.add(jcb_pr);
Object city[]={"宁波","杭州","温州"};
JComboBox jcb_city=new JComboBox(city);
pan.add(jcb_city);
JButton jb_add=new JButton("添加");
jb_add.addActionListener(this);
pan.add(jb_add);
this.setVisible(true);
}
public static void main(String[] args) {
new userframe();
}
public void actionPerformed(ActionEvent e) {
String str="";
str+=tx_number.getText()+","+tx_name.getText()+",";
if(rb1.isSelected())
str+=rb1.getText()+",";
else
str+=rb2.getText();
str+=jcb_pr.getSelectedItem();
str+=jcb_city.getSelectedItem();
System.out.println();
this.nunber++;
this.tx_number.setText(Integer.toString(this.nunber));
this.tx_name.setText("姓名");
}
public void itemStateChanged(ItemEvent e) {
// if(e.getItem()=="浙江")//
if(jcb_pr.getSelectedIndex()==0)
{
jcb_city.removeAllItems();
jcb_city.addItem("杭州市");
jcb_city.addItem("宁波市");
jcb_city.addItem("温州市");
}
// if(e.getItem()=="江苏");//
if(jcb_pr.getSelectedIndex()==1)
{
jcb_city.removeAllItems();
jcb_city.addItem("南京市");
jcb_city.addItem("镇江市");
jcb_city.addItem("扬州市");
}
//if(e.getItem()=="湖南");//
if(jcb_pr.getSelectedIndex()==2)
{
jcb_city.removeAllItems();
jcb_city.addItem("长沙市");
jcb_city.addItem("湘漂市");
jcb_city.addItem("株州市");
}
}
}