Java Memorandom- Graphics.drawImage

In paint(Graphics g) call back, use drawImage() to draw an image. It is crucial to specify ImageObserver parameter.

I mistakenly passed a null to the parameter, and the drawing was not done properly. It renders only when any other event forces to repaint. When the parameter was properly set, the rendering happens correctly so that the image shows up from the beginning.

public class MyPanel extends Panel
{
    public
void paint(Graphics g)
    {
        if(
null != image)
        {
           
g.drawImage(image, imageX, imageY, this);
        }
    }
}

Graphics.drawImage
Interface ImageObserver

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <code> <cite> <ul> <ol> <li> <dl> <dt> <dd> <p>
  • Lines and paragraphs break automatically.
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.