passing value from jcombobox to other classes?

Hi guys,

I have an Jcombobox with an actionlistener set up in a class called "boxSelected", so that when the user clicks on the choice they're after the result is sent to a jtext area.

publicclass box2listenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent e){

if(e.getSource()==queryBox2){

int selectedIndex = queryBox2.getSelectedIndex();

String box2Selected = queryBox2.getSelectedItem().toString();

System.out.println("Selected: "+box2Selected);

String newline ="\n";

textArea3.append(box2Selected + newline);

}

}

};

The class with the actionlistener is contained within another class, one called Editor.

My question is, can I pass this new string value, boxSelected, for use in another class? I'm trying to create a new .java file and pass this string value for use with a class there, so I can parse it into some queries.

I've been at this a wee while and am still very new. Thanks for any help or code you could give me here to sort this, any help would be great.

[1535 byte] By [jtowersa] at [2007-11-26 17:08:03]
# 1
Yes, you'd just need to set up a constructor in your other class that took a String parameter, and pass it into an instance variable when you called that constructor to instantiate the class.
DavidKNa at 2007-7-8 23:35:53 > top of Java-index,Java Essentials,New To Java...
# 2

Hey thanks a lot for your quick reply.

I hate to say it though; I'm afraid I haven't got much of an idea what a lot of that meant. Would it be bold of me to ask to have it spelt out to me a bit further? At the moment I'm using tutorials but I'm not finding a lot of these concepts particularly clear at my level of experience.

Thanks again.

jtowersa at 2007-7-8 23:35:53 > top of Java-index,Java Essentials,New To Java...
# 3

Well you need to call the Class with your variables as mentioned.

like so

OtherClassName.MethodNameFromOtherClass(selectedIndex, someOtherVal)

You can do it either through it's constructor or through a method that excepts the arguments you pass in.

If you don't understand this then stop using Swing and action listeners for now and learn about whatever you feel you don't understand. Chances are you won't be even using Swing on-site.

Mike

kikemellya at 2007-7-8 23:35:53 > top of Java-index,Java Essentials,New To Java...