Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Graphics g = null

Thread view: 
bob8000 - 17 Mar 2007 17:08 GMT
Hello to All

Could someone tell me why

Graphics g = getGraphics();

would equal zero

I know it should equal something like

sun.java2d.SunGraphics2D[some other stuff in here]

I am completly stumped on this one

BOB8000
Efi Merdler - 17 Mar 2007 17:29 GMT
> Hello to All
>
[quoted text clipped - 11 lines]
>
> BOB8000

Hi,
Make sure you are calling getGraphics after the form was initialized
and displayed.

Efi
Knute Johnson - 17 Mar 2007 17:31 GMT
> Hello to All
>
[quoted text clipped - 11 lines]
>
> BOB8000

Are you calling getGraphics() on a Component?  Is it visible?  Do you
know where to find the API documentation?

Signature

Knute Johnson
email s/nospam/knute/

Nigel Wade - 19 Mar 2007 10:48 GMT
> Hello to All
>
> Could someone tell me why
>
> Graphics g = getGraphics();

Called on what?
Has whatever you are invoking the method on been realized? A component which
hasn't yet been realized has no Graphics, and getGraphics() will return null.

> would equal zero

zero, or null? It should never be zero.

> I know it should equal something like
>
> sun.java2d.SunGraphics2D[some other stuff in here]

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Tor Iver Wilhelmsen - 22 Mar 2007 19:41 GMT
På Sat, 17 Mar 2007 17:08:37 +0100, skrev bob8000 <bob8000@hotmail.co.uk>:

> Could someone tell me why
>
> Graphics g = getGraphics();
>
> would equal zero

You mean null? getGraphics() returns null until the component has a  
"peer". If you need to pick it up for some code, either do so in  
addNotify() or in paint()/paintComponent(), though the latter might be  
"too late" for your needs.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.