Hi, I have been scratching my head for a couple of hours wondering why my Japplet isnt working. The problem is, the second time I select the first combobox, the second combobox does not update its content and hangs. I am not sure where its looping to and have tried to trace it out. The code is as follows.
public class brake extends JApplet implements ActionListener {
JComboBox state, traintype;
Container c;
String[] sNSW = { "Select", "Titan", "HMT" };
String[] sVIC = { "Select", "Nokia", "Sony" };
TextArea display = new TextArea(10, 80);
String str;
JComboBox src;
public void init(){
String[] states = { "Select", "NSW", "VIC"};
state = new JComboBox(states);
state.addActionListener(this);
traintype = new JComboBox();
traintype.addActionListener(this);
str = "";
src= null;
c = getContentPane();
c.setLayout(new FlowLayout());
c.add(state);
c.add(traintype);
display.setEditable(false);
c.add(display);
}
public void actionPerformed(ActionEvent e) {
display.setText("");
str ="";
src = (JComboBox) e.getSource();
if (src.equals(state)) {
str = (String) state.getSelectedItem();
display.append("In state combo :" +str+"\n");
if(str.equals("Select")){
traintype.setEnabled(false);
}else if(str.equals("NSW")){
traintype.setEnabled(true);
traintype.removeAllItems();
for (int i = 0; i < sNSW.length; i++) {
traintype.addItem(sNSW[i]);
}
}else if(str.equals("VIC")){
traintype.setEnabled(true);
traintype.removeAllItems();
for (int i = 0; i < sVIC.length; i++) {
traintype.addItem(sVIC[i]);
}
}else{display.append("ERORR: State not chosen" + "\n");}
}else if(src.equals(traintype)){
str = (String) traintype.getSelectedItem();
display.append("In traintype combo :" +str+"\n");
if(str.equals("Select")){
// traintype.setEnabled(false);
display.append("if :"+"\n");
}else{
display.append("else :"+"\n");
}
}else{display.append("ERORR: getSource Failed" + "\n");}
display.append("End event"+"\n");
}/*end itemStateChanged */
}/*end program */