aspose file tools*
The moose likes Java in General and the fly likes Making a String accessible to other classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Making a String accessible to other classes" Watch "Making a String accessible to other classes" New topic
Author

Making a String accessible to other classes

Chris Fetterley
Ranch Hand

Joined: May 13, 2003
Posts: 51
I am designing a three in one application that needs Three different String and int variables throughout it. Screen with a drop down menu that will allow me to select which string and int I want to use and then starts the application normally. There will actually be three different variation of the program...I will put some examples down below.
The drop down menu I have looks like this....
public boolean action(Event event, Object object) {

if (event.target == station) {
String selection = station.getSelectedItem();

if (selection.equals("Choose "))
doChoice0Action();

else if (selection.equals("Station1 "))
doChoice1Action();

else if (selection.equals("Station2 "))
doChoice2Action();
else if (selection.equals("Station3 "))
doChoice3Action();

return(true);
}
else
return(false);
}
public doChoice0Action() {
l = 0;
}
public void doChoice1Action() {
l = 3;
locat = "Station1";
}
public void doChoice2Action() {
l = 1;
locat = "Station2";
}
public void doChoice3Action() {
l = 2;
locat = "Station3";
}
locat is a string and l is an int this is defined in my Login.java page.
what I want now is to have l and locat available for all of my other .java pages. How do I set this up?
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Chris
Two options I can think of,
1. Creating two public static variables in the current class and then updating as you are in the doAction methods...the issue would be- "how the other classes know about the change?"
2. writing PropertyChangeListeners for this two property changes (var l and the other var) and throw PropertyChange event from this object whenever you change those vars in doAction method...
I guess 2nd one is a better solution.
Regards
Maulin
Chris Fetterley
Ranch Hand

Joined: May 13, 2003
Posts: 51
Thanks you were a huge help!! have it working now.
Chris Fetterley
Ranch Hand

Joined: May 13, 2003
Posts: 51
here is what I had to call in the beginning of each page to reference the location... on each page.
public static String location= String.valueOf(Login.locat);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making a String accessible to other classes