Using String variable values to call methods

I have some string variables being sent to a method that uses their values to call getText();. Problem is that I don't know how to use the values of the variables rather than the variable names when using getText(); or any other method for that matter. Sample code below:

public void SliderFunction(String north, String east, String south, String west) {

north.getText();

east.getText();

south.getText();

west.getText();

}

But of course this tries to look for north.getText(); etc instead of using the value of the 'north' String.

Any clues on how this is done?

Thanks,

Jon

[643 byte] By [JonMidhira] at [2007-11-27 5:48:08]
# 1

You can't do that the way you're trying to. What you can do is use a Map. You store the objects that have the getText() method in the map as values, using the String as the key. That way you can use the north String to retrieve the Object mapped to north.

http://www.google.com/search?q=java+map

hunter9000a at 2007-7-12 15:33:17 > top of Java-index,Java Essentials,Java Programming...
# 2
It's just not the object oriented way to do things. You should be passing object references into this method, not strings. If you read a string from a text source that indicates one of a set of objects then you find the object as soon as you get the string. Or you might use an enum type.
malcolmmca at 2007-7-12 15:33:17 > top of Java-index,Java Essentials,Java Programming...
# 3

I understand ok, but I've been trying and i'm not sure how to implement this.

If I use the north string to reference a value in the HashMap how do I then apply getText() to this? Surely I run into the same problem as using Strings.

If I pass Objects into the method it's the same.

What I'm basically trying to do is, when the user presses a button the program returns the values on the adjacent buttons. I can then use this data to setText() later.

JonMidhira at 2007-7-12 15:33:17 > top of Java-index,Java Essentials,Java Programming...
# 4
Give each button it's own ActionListener, which knows what objects need to be referenced.
malcolmmca at 2007-7-12 15:33:17 > top of Java-index,Java Essentials,Java Programming...
# 5
I have done that alright, so i'm now sending object references to the method above instead of strings but I have to admit i'm still stumped as to how to use that information in the method to refer back to the values on the other buttons.Any help appreciated.
JonMidhira at 2007-7-12 15:33:17 > top of Java-index,Java Essentials,Java Programming...
# 6
This thread makes no sense to me whatsoever. Maybe I'm missing something.Did you ever clearly describe what you are trying to do, what your goal is?
Hippolytea at 2007-7-12 15:33:17 > top of Java-index,Java Essentials,Java Programming...
# 7
Actually I just nailed it.Thanks a lot to you guys.I used Objects to refer to the text on each button then sent those to the method using ActionListeners.Just got a bit confused and couldn't see the wood for the trees.Many thanks!
JonMidhira at 2007-7-12 15:33:17 > top of Java-index,Java Essentials,Java Programming...