Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help With Graphics.
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TerranceN




PostPosted: Fri May 28, 2010 11:15 pm   Post subject: RE:Help With Graphics.

Do you understand the difference between static and non-static members?

Static means that it belongs to the class in general. Non-static means it belongs to a specific instance of a class. For example, you may have a class that defines an Enemy. You would make things that are different to each enemy (such as position, direction, etc) non-static, because they belong to each individual enemy. You would make things that are the same for every instance of the class (like a colour constant, assuming all the enemies are the same colour).

In the same way, the graphics object can be different for each component, therefore anything that uses it must be non-static.

So how do you use it from main, which has to be static? You create a new instance of the object:

Java:
ClassName VariableName = new ClassName();


Then you can call a public non-static method that deals with instance specific things like this:

Java:
VariableName.MethodName();


Hope that helps.
Sponsor
Sponsor
Sponsor
sponsor
Unnamed.t




PostPosted: Sat May 29, 2010 11:16 am   Post subject: Re: Help With Graphics.

Yeah I understand the differences between static and non-static methods

Thank you for showing me how to make new Instances. It makes perfect sense and my program is working fine now. Thank you again, it helped a lot.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 17 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: