Click to See Complete Forum and Search --> : getGraphics() returning null


weaver
March 6th, 2000, 09:08 AM
I am trying to load an image into an application and display it in my program. When I try to get the graphics in the example below, the graphics object is null. How can I get the graphics?

Toolkit tk = getToolkit();
bg = Color.blue;
setBackground( bg );
image1 = tk.getImage( "images/New.gif" );
g.drawImage( image1, 3, 3, parent );


-------------------------------------------
T. Sean Ryan
http://rastos0.kjm.htmlplanet.com

kib63613
March 6th, 2000, 05:51 PM
You need use Component.getGraphics() to get the Graphics context for
the component before you paint something on the component.
good luck
Alfred Wu

poochi
March 6th, 2000, 06:38 PM
you cant get the graphics inside a component's constructor. Check whether you have
put this code inside the Component's constructor.