Hi, I'm trying to have two string arrays (State, County) based on the first selection puts the counties into the second choice box. I'm trying to combine my classes within my applet and I'm having problems with my applet not initializing and I'm unsure where I'm going wrong. If you could please help out a very distressed programmer that would great. Here is the code, several classes at the bottom help with loading and clearing the choice boxes. My main goal is to initialize the choice boxes from within my applet not from another applet or class, I have done that. I need it done this way so that I may use the second choice box answers within my applet. <br>
<br>
Thanks in advance, <br>
<br>
MAIN APPLET <br>
<br>
import java.applet.*;<br>
import java.awt.*;<br>
import java.awt.event.*;<br>
<br>
public class state extends Applet {<br>
<br>
//subChoice sub;<br>
cub sub;<br>
Applet a; <br>
<br>
//setup the layout<br>
public void init() {<br>
setLayout(new FlowLayout());<br>
a = this;<br>
stateData sd;<br>
sd = new stateData();<br>
sub = new cub(sd.StateNames, sd.CityStateNames);<br>
add(cub);<br>
} <br>
<br>
}<br>
<br>
class cub extends Component {<br>
Applet a;<br>
String[] category; // Category Names;<br>
String[][] subCategory; // Sub-Category details<br>
Choice left; // Choice for category<br>
Choice right; // Choice for sub-category<br>
<br>
public cub (String[] category, String[][] subCategory) {<br>
this.category = category;<br>
this.subCategory = subCategory;<br>
this.a = a; <br>
<br>
//setup the left Choice<br>
left = new Choice();<br>
for (int i = 0; i < category.length; i++ )<br>
left.add(category<i>);<br>
a.add(left);<br>
left.addItemListener(new leftHandler(this));<br>
updateRight(subCategory[0]);<br>
<br>
//setup the right choice<br>
//with the first (position 0) set of sub-Categories <br>
right = new Choice();<br>
a.add(right);<br>
right.addItemListener(new rightHandler(this));<br>
updateRight(subCategory[0]);<br>
}<br>
<br>
// update the right choices<br>
public void updateRight (String[] s) {<br>
right.removeAll();<br>
for (int i = 0; i < s.length; i++ )<br>
right.add(s<i>);<br>
right.select(0);<br>
} <br>
<br>
}<br>
<br>
class leftHandler implements ItemListener {<br>
<br>
cub s;<br>
<br>
public leftHandler (cub s) {<br>
this.s = s;<br>
}<br>
<br>
public void itemStateChanged (ItemEvent e) {<br>
int i = s.left.getSelectedIndex();<br>
s.updateRight(s.subCategory<i>);<br>
s.a.showStatus("State = " + s.left.getSelectedItem());<br>
} <br>
}<br>
<br>
class rightHandler implements ItemListener {<br>
<br>
cub s; <br>
<br>
public rightHandler (cub s) {<br>
this.s = s;<br>
}<br>
<br>
public void itemStateChanged (ItemEvent e) {<br>
s.a.showStatus("City = " + s.right.getSelectedItem());<br>
<br>
} <br>
}<br>
<br>
<br>
<br>
<p> Courtney<br><a href=mailto: ceaton@lrp.com> ceaton@lrp.com</a><br><a href= > </a><br>
<br>
Thanks in advance, <br>
<br>
MAIN APPLET <br>
<br>
import java.applet.*;<br>
import java.awt.*;<br>
import java.awt.event.*;<br>
<br>
public class state extends Applet {<br>
<br>
//subChoice sub;<br>
cub sub;<br>
Applet a; <br>
<br>
//setup the layout<br>
public void init() {<br>
setLayout(new FlowLayout());<br>
a = this;<br>
stateData sd;<br>
sd = new stateData();<br>
sub = new cub(sd.StateNames, sd.CityStateNames);<br>
add(cub);<br>
} <br>
<br>
}<br>
<br>
class cub extends Component {<br>
Applet a;<br>
String[] category; // Category Names;<br>
String[][] subCategory; // Sub-Category details<br>
Choice left; // Choice for category<br>
Choice right; // Choice for sub-category<br>
<br>
public cub (String[] category, String[][] subCategory) {<br>
this.category = category;<br>
this.subCategory = subCategory;<br>
this.a = a; <br>
<br>
//setup the left Choice<br>
left = new Choice();<br>
for (int i = 0; i < category.length; i++ )<br>
left.add(category<i>);<br>
a.add(left);<br>
left.addItemListener(new leftHandler(this));<br>
updateRight(subCategory[0]);<br>
<br>
//setup the right choice<br>
//with the first (position 0) set of sub-Categories <br>
right = new Choice();<br>
a.add(right);<br>
right.addItemListener(new rightHandler(this));<br>
updateRight(subCategory[0]);<br>
}<br>
<br>
// update the right choices<br>
public void updateRight (String[] s) {<br>
right.removeAll();<br>
for (int i = 0; i < s.length; i++ )<br>
right.add(s<i>);<br>
right.select(0);<br>
} <br>
<br>
}<br>
<br>
class leftHandler implements ItemListener {<br>
<br>
cub s;<br>
<br>
public leftHandler (cub s) {<br>
this.s = s;<br>
}<br>
<br>
public void itemStateChanged (ItemEvent e) {<br>
int i = s.left.getSelectedIndex();<br>
s.updateRight(s.subCategory<i>);<br>
s.a.showStatus("State = " + s.left.getSelectedItem());<br>
} <br>
}<br>
<br>
class rightHandler implements ItemListener {<br>
<br>
cub s; <br>
<br>
public rightHandler (cub s) {<br>
this.s = s;<br>
}<br>
<br>
public void itemStateChanged (ItemEvent e) {<br>
s.a.showStatus("City = " + s.right.getSelectedItem());<br>
<br>
} <br>
}<br>
<br>
<br>
<br>
<p> Courtney<br><a href=mailto: ceaton@lrp.com> ceaton@lrp.com</a><br><a href= > </a><br>