Evening
I am writing a small program to present a UI that when selecting 1 item from a drop down list then gives the user a selection of data relating to their selection. For instance if Ford cortina was selected from a list of Ford cars on screen in the GUI would be presented in text boxes the Cc, Tire pressure, MPg etc etc
My program has 3 classes to present this, the Main class to get it all running the UI class that builds the GUI and the data class that holds the Stringarrays of data for each model of car. The UI class calls the information from the data class.
The problem I have is making use of the selection from the drop down list to then reference the correct stringArray in the other class.
Any advice or help much appreciated.
Ian
//instance version
sa = new StringArrays(); sa.Cortina;//example
public void actionPerformed(ActionEvent ae)
{
int idx = list.getSelectedIndex();
if(idx != -1)
jlab.setText("You selected " + model.getElementAt(idx));
choice = model.getElementAt(idx);//set variable choice to the selection in this case Cortina
//should choice be an object or a string? (neither work).
System.out.println("test point here " + choice);// Just an on screen tester that displays current definition of choice = Cortina.
if(idx == 0)
{
jtxt1.setText("Info 1 = "+ sa.Cortina[0]);// if this was sa.choice[0] it would not work as it looks for a StringArray called choice!
jtxt2.setText("Info 2 = " + sa.Cortina[1]);
}
else
if(idx>0)
{
jlab.setText("No Make selected");
jtxt1.setText("reset");
jtxt2.setText("reset ");
}