[java] Classess can access Applet variables??

Started by
0 comments, last by jamesweston29 23 years, 9 months ago
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
Advertisement
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

}
}
author of the Helping Phriendly Book

This topic is closed to new replies.

Advertisement