[java] Classess can access Applet variables??
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
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
}
}
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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement