Hi ,
I am trying to define global(commonly shared variables/strings between different classes) variables to be shared and can be manipulated between many classes, here is the example:
// this class suppose to hold the definition and initialisation of the global variables
import java.awt.*;
public class GlobalVars
{
public
String gstrx ; // this is my global variable to be modified in the next class
public void init()
{
gstrx = "Hi";
System.out.print(" gstrx from class GlobalVars =" + gstrx );
}
}
The above class was saved in file GlobalVars.java and loaded to the project.
import java.awt.*;
import java.applet.Applet;
public class class1 extends
Applet {
GlobalVars MyGclass = new GlobalVars();
String strx1;
String strx2;
public void init()
{
MyGclass.init();
strx1 = MyGclass.gstrx + " from me ";
System.out.print("strx1 from class1 =" + strx1);
//here is where I need to modify gstrx in this class and in GlobalVars class
MyGclass.gstrx = "Welcome from me "; //this will modify it for this class only!
System.out.print("MyGclass.gstrx = " + MyGclass.gstrx );
strx2 = MyGclass.gstrx;
System.out.print("strx2 from class1 = " + strx2);
}
}
The above class was saved in file class1.java and loaded to the project.
What really I wanted was that �strx2� would show �Welcome from me�, which means I have modified the global variable in my global class �MyGclass�. Any help on this?.