Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making a String accessible to other classes

 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you were a huge help!! have it working now.
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic