Hi Pavan,

  what probably happens is that you're trying to display
  an image which is not fully loaded at that time. Try
  to modify your code to use MediaTracker class.
  Here is an example:

import java.awt.*;
import java.awt.image.*;

public class Test extends Frame {

    Image image;
    public Test() {
        image = Toolkit.getDefaultToolkit().getImage("duke2.gif");
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(image, 1);
        try {
            tracker.waitForAll();
        } catch (Exception e) {
            image = null;
            System.err.println("Can't load image");
        }
        setSize(200, 200);
        setVisible(true);
    }

    public void paint(Graphics g0) {
        if (image != null) {
            g.drawImage(image, 50, 50, null);
        }
    }

    public static void main(String argv[]) {
        new Test();
    }
}

  Thank you,
    Dmitri

On Tue, Sep 12, 2000 at 09:40:0p -0700, Pavan Sulibhavi wrote:
 > Hi guys,
 >    I want to display an image within a frame. this is how i
 > am trying to do it.
 > import java.awt.*;
 >
 > public class ImageDemo extends Frame
 > {
 >
 >     MyCanvas canvas;
 >     Image image = null;
 >     public ImageDemo()
 >     {
 >         image =
 > getParent().getToolkit().getImage("Software.jpg");
 >         canvas = new MyCanvas(image);
 >         add(canvas);
 >     }
 >     public static void main(String args[])
 >     {
 >
 >         ImageDemo app = new ImageDemo();
 >         app.resize(500, 500);
 >         app.show();
 >         app.toFront();
 >        }
 > }
 > class MyCanvas extends Canvas
 > {
 >     Image image;
 >     public MyCanvas(Image img)
 >    {
 >         image = img;
 >         setBackground(Color.white);
 >         resize(500, 500);
 >     }
 >     public void paint(Graphics g)
 >     {
 >       g.drawImage(image, 0, 0, this);
 >     }
 > }
 >    I get the frame but not the image. why? Can somebody
 > make a correction and let me know. please........ Can
 > anybody give me some pointers.
 > pavan
 >
 >
 > __________________________________________________
 > Do You Yahoo!?
 > Yahoo! Mail - Free email you can access from anywhere!
 > http://mail.yahoo.com/
 >
 > ===========================================================================
 > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
 > of the message "signoff JAVA2D-INTEREST".  For general help, send email to
 > [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to