Archived

This topic is now archived and is closed to further replies.

[java] Classess can access Applet variables??

This topic is 6410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I was wordering if a custom class can access the variables of the applet. ie If I create a class such as class Player { int xPos; int YPos; }; Can I access the "global" valraibles of the main applet. I would appreciate any help. Thanx

Share this post


Link to post
Share on other sites
If this class is a inner class it can automatically, or sometimes you might have to use this syntax to access a outer classes variables from a inner class. Say
OuterClassName.this.variableName

Another way to do it without inner classes is to pass a pointer or a refrence to the applet in.
class Player
{
int xPos;
int yPos;
JApplet applet;


public Player(JApplet applet)
{
this.applet = applet;//now you have access through applet

}
}

Share this post


Link to post
Share on other sites