removeAllItems()的用法
											请各位高手帮小弟一个忙:JComboBox类的removeAllItems()怎么用啊(谢谢!!)										
					
	
				
											import java.awt.*; 
import java.awt.event.*; 
import javax.swing.event.*; 
import javax.swing.*; 
class YAHOO extends JFrame implements ActionListener,ItemListener 
{ 
JTextField jtf1,jtf2,jtf3,jtf4,jtf5; 
JPasswordField jpf1,jpf2; 
JLabel j1,j2,j3,j4,j5,j6,j7,j8,j9,j10,j11,j12,j13; 
CheckboxGroup bg; 
Checkbox jrb1,jrb2; 
JButton jb1,jb2; 
JComboBox jcb1,jcb2,jcb3; 
JPanel jp=new JPanel(); 
String s8; 
GridBagLayout gb; 
GridBagConstraints gbc; 
public YAHOO() 
{ 
gb=new GridBagLayout(); 
getContentPane().setLayout(gb); 
gbc=new GridBagConstraints(); 
gbc.insets=new Insets(10,10,10,10); 
jtf1=new JTextField(10); 
jtf2=new JTextField(10); 
jtf3=new JTextField(10); 
jtf4=new JTextField(10); 
jtf5=new JTextField(10); 
jpf1=new JPasswordField(10); 
jpf2=new JPasswordField(10); 
Icon ic=new ImageIcon("yahoo.gif"); 
j13=new JLabel(ic); 
j1=new JLabel("Registration Form"); 
Font f=new Font("Georgia",Font.BOLD,28); 
j1.setFont(f); 
j2=new JLabel("Yahoo ID:"); 
j3=new JLabel("Password:"); 
j4=new JLabel("Retype Password:"); 
j5=new JLabel("Fist Name:"); 
j6=new JLabel("Last Name:"); 
j7=new JLabel("Gender:"); 
j8=new JLabel("Birthday:"); 
j9=new JLabel("Country/Region:"); 
j10=new JLabel("State:"); 
j11=new JLabel("@Yahooc.com"); 
j12=new JLabel("(Month,dd,yyyy)"); 
bg=new CheckboxGroup(); 
jrb1=new Checkbox ("Male",true,bg); 
//jrb1.setSelected(true); 
jrb2=new Checkbox ("Female",false,bg); 
//jrb1.setActionCommand("temp1"); 
//jrb2.setActionCommand("temp2"); 
//jrb1.addItemListener(this); 
//jrb2.addItemListener(this); 
jb1=new JButton("OK"); 
jb2=new JButton("Exit"); 
jcb1=new JComboBox(); 
jcb2=new JComboBox(); 
jcb2.setActionCommand("temp"); 
jcb3=new JComboBox(); 
jcb1.addItem("Janury"); 
jcb1.addItem("February"); 
jcb1.addItem("Mar"); 
jcb1.addItem("April"); 
jcb1.addItem("May"); 
jcb1.addItem("June"); 
jcb1.addItem("July"); 
jcb1.addItem("August"); 
jcb1.addItem("September"); 
jcb1.addItem("October"); 
jcb1.addItem("November"); 
jcb1.addItem("December"); 
jcb2.addItem("<Select country>"); 
jcb2.addItem("Austraila"); 
jcb2.addItem("India"); 
jcb2.addItem("United Kingdom"); 
jcb2.addItem("United States"); 
jcb2.addActionListener(this); 
jb1.addActionListener(this); 
jb2.addActionListener(this); 
gbc.fill=GridBagConstraints.HORIZONTAL; 
AddComponent(j1,0,2,1,2); 
AddComponent(j13,1,0,3,7); 
AddComponent(j2,5,0,1,1); 
AddComponent(jtf1,5,1,1,1); 
AddComponent(j11,5,2,1,1); 
AddComponent(j3,6,0,1,1); 
AddComponent(jpf1,6,1,1,1); 
AddComponent(j4,7,0,1,1); 
AddComponent(jpf2,7,1,1,1); 
AddComponent(j5,8,0,1,1); 
AddComponent(jtf2,8,1,1,1); 
AddComponent(j6,9,0,1,1); 
AddComponent(jtf3,9,1,1,1); 
AddComponent(j7,10,0,1,1); 
AddComponent(jrb1,10,1,1,1); 
AddComponent(jrb2,10,2,1,1); 
AddComponent(j8,11,0,1,1); 
AddComponent(jcb1,11,1,1,1); 
//gbc.fill=GridBagConstraints.NONE; 
AddComponent(jtf4,11,2,1,1); 
//gbc.fill=GridBagConstraints.NONE; 
AddComponent(jtf5,11,3,1,1); 
//gbc.fill=GridBagConstraints.HORIZONTAL; 
AddComponent(j12,11,4,1,1); 
AddComponent(j9,12,0,1,1); 
AddComponent(jcb2,12,1,1,1); 
AddComponent(j10,13,0,1,1); 
AddComponent(jcb3,13,1,1,1); 
AddComponent(jb1,15,2,1,1); 
//gbc.fill=GridBagConstraints.NONE; 
//gbc.weightx=0; 
AddComponent(jb2,15,3,1,1); 
setBounds(0,0,800,700); 
} 
public void itemStateChanged (ItemEvent e) 
{ 
} 
public void actionPerformed(ActionEvent e) 
{ 
String s8="Male"; 
if(e.getActionCommand()=="Exit") 
{ 
System.exit(0); 
} 
else if(e.getActionCommand()=="temp") 
{ 
int num=jcb2.getSelectedIndex(); 
if(num==1) 
{ 
jcb3.removeAllItems(); 
jcb3.addItem("Austraila1"); 
jcb3.addItem("Austraila2"); 
jcb3.addItem("Austraila3"); 
} 
if(num==2) 
{ 
jcb3.removeAllItems(); 
jcb3.addItem("India1"); 
jcb3.addItem("India2"); 
jcb3.addItem("India3"); 
} 
if(num==3) 
{ 
jcb3.removeAllItems();      //就是这里
jcb3.addItem("United Kingdom1"); 
jcb3.addItem("United Kingdom2"); 
jcb3.addItem("United Kingdom3"); 
} 
if(num==4) 
{ 
jcb3.removeAllItems(); 
jcb3.addItem("United Stetas1"); 
jcb3.addItem("United Stetas2"); 
jcb3.addItem("United Stetas3"); 
} 
} 
else if(e.getActionCommand()=="OK") 
{ 
String s1=new String(jtf1.getText()); 
String s2=new String(jpf1.getText()); 
String s3=new String(jpf2.getText()); 
String s4=new String(jtf2.getText()); 
String s5=new String(jtf3.getText()); 
String s6=new String(jtf4.getText()); 
String s7=new String(jtf5.getText()); 
if(s1.length()==0) 
{ 
JOptionPane.showMessageDialog(null,"Please Enter login ID"); 
jtf1.setFocusable(true); 
return; 
} 
if(!((s1.charAt(0)>=´a´ && s1.charAt(0)<=´z´)||(s1.charAt(0)>=´A´ &&s1.charAt(0)>=´Z´))) 
{ 
JOptionPane.showMessageDialog(null,"Please Enter vaild login ID starting With character"); 
jtf1.setFocusable(true); 
return; 
} 
if(s2.length()<8) 
{ 
JOptionPane.showMessageDialog(null,"Please Enter password of 8 character"); 
jpf2.setFocusable(true); 
return ; 
} 
if(!(s2.equals(s3))) //直接使用String赋值不对,因为不是对象必须先NEW一下! 
{ 
JOptionPane.showMessageDialog(null,"Please Re-enter password"); 
jpf2.setFocusable(true); 
return; 
} 
if(jrb1.getState()==true) 
{ 
s8="Male"; 
} 
else 
{ 
s8="Female"; 
} 
System.out.println(e.getSource()); 
JOptionPane.showMessageDialog(null,"Yahoo ID:"+s1+"\n" 
+"Password:"+s2+"\n" 
+"Name:"+s4+" "+s5+"\n" 
+"Birthday :"+jcb1.getSelectedItem()+"/"+s6+"/"+s7+"\n" 
+"Country/Region:"+jcb1.getSelectedItem()+"\n" 
+"Gender:"+s8+"\n" 
+"State:"+jcb3.getSelectedItem()); 
} 
} 
public static void main(String args[]) 
{ 
YAHOO frm=new YAHOO(); 
frm.show(); 
} 
public void AddComponent(Component c,int row,int col,int nrow,int ncol) 
{ 
gbc.gridx=col; 
gbc.gridy=row; 
gbc.ipadx=3; 
gbc.ipady=5; 
gbc.gridwidth=ncol; 
gbc.gridheight=nrow; 
gb.setConstraints(c,gbc); 
getContentPane().add(c); 
} 
} 
										
					
	
	
	
			


 
											





 
	    

 
	



