Computer Science Canada getGraphics () Help |
Author: | Johnathon [ Thu Jan 08, 2009 9:16 pm ] | ||
Post subject: | getGraphics () Help | ||
Hey again. I've been (slowly) working on my Networked LAN game, and I've hit a bit of a road bump. I'm trying to add a (very basic) GUI. Only problem is that I am unable to call my Graphics. It seems that It's forcing me to use a static method (Protected, ect lead to an error with my main being unable to access a non-static method). However, it seems that my getGraphics will not work in a static method. Any help would be wonderful... Im likely just overlooking something VERY simple. Here's my code, since I'm not afraid of anyone stealing it, quite yet.
|
Author: | OneOffDriveByPoster [ Thu Jan 08, 2009 9:53 pm ] |
Post subject: | Re: getGraphics () Help |
You need an instance of your class. You can create one in main(). You can then call a non-static mainMenu() on that instance. |
Author: | Johnathon [ Thu Jan 08, 2009 10:03 pm ] | ||
Post subject: | Re: getGraphics () Help | ||
OneOffDriveByPoster @ Thu Jan 08, 2009 9:53 pm wrote: You need an instance of your class. You can create one in main(). You can then call a non-static mainMenu() on that instance.
Im not sure if it's just your wording, but mind giving me an example...? Ive been trying to comprehend what you mean, but it's not going so well... All the came to mind was:
|
Author: | OneOffDriveByPoster [ Thu Jan 08, 2009 10:24 pm ] | ||
Post subject: | Re: getGraphics () Help | ||
|
Author: | Johnathon [ Thu Jan 08, 2009 10:44 pm ] | ||||||
Post subject: | Re: getGraphics () Help | ||||||
OneOffDriveByPoster @ Thu Jan 08, 2009 10:24 pm wrote:
Which now leads to a nice java.lang.NullPointerException at ClientTest.mainMenu(ClientTest.java:37)
at ClientTest.main(ClientTest.java:23)
|
Author: | [Gandalf] [ Fri Jan 09, 2009 2:06 am ] |
Post subject: | RE:getGraphics () Help |
You'll have to show us your complete updated code, but it sounds like your method doesn't take the required Graphics or Graphics2D (or isn't calling that parameter 'g'). Edit: glancing a bit closer at your code... your Graphics object is called 'layout', not 'g'. |
Author: | Johnathon [ Fri Jan 09, 2009 9:01 am ] | ||
Post subject: | Re: RE:getGraphics () Help | ||
Quote: You'll have to show us your complete updated code, but it sounds like your method doesn't take the required Graphics or Graphics2D (or isn't calling that parameter 'g').
Edit: glancing a bit closer at your code... your Graphics object is called 'layout', not 'g'. Since this is only a ... test code, I felt that some things should be changed for simplicity, and better understandings, so I did change my Graphics to g from layout. Since you requested it, here is my new code. Ignore the drawOval, it's simply a method for me to ... debug, and figure out my barings.
|
Author: | [Gandalf] [ Sat Jan 10, 2009 3:00 am ] |
Post subject: | RE:getGraphics () Help |
There's a problem with your getGraphics() call, it's returning null. Let's see what the Java Documentation has to say about that... Quote: Creates a graphics context for this component. This method will return null if this component is currently not displayable.
May I suggest redesigning your game to use Swing, and model it around a JFrame? |