"get image " in a frame!!!!

Hello expert;
   What i can do to use function "get image " in a frame.I have try it before but after i compiled it, the compiler show me an error. The error message is "no getImage function in class frame". So what i can do if i want to call a ".gif" file into a frame.
 Thanks to answer my question .
tseauAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heyhey_Commented:
Image Toolkit.getDefaultToolkit().getImage(String filename)

Image Toolkit.getDefaultToolkit().getImage(URL url)
0
OviCommented:
import java.awt.*;
import java.io.*;
public class cFrame extends Frame {
Image img = null;

    public cFrame() {
        super();
        this.setSize(400, 400);
        this.setLocation(100, 100);
        this.setBackground(Color.green);
        this.setLayout(null);
        img = readImg("YourGifFile.gif");
        repaint();
    }

    public Image readImg(String file) {
        Image img = null;
        byte[] stream=new byte[100000];
        try {
            FileInputStream fis = new FileInputStream (file);
            int x = fis.read(stream);                
        } catch (EOFException e) {
            System.out.println("All is ok,  ...Done");
        } catch (Exception e) {
            System.out.println("All is wrong,  ...Failed "+e.toString());
        }
        Toolkit atk;
        atk = java.awt.Toolkit.getDefaultToolkit();
        img = atk.createImage(stream);
        return img;
    }

    public void update(Graphics g) {
        paint(g);
    }

    public void paint(Graphics g) {
        if(img!=null)
            g.drawImage(img, 0, 0, size().width, size().height, this);
    }    
    public static void main(String arg[]) {
        cFrame x = new cFrame();
        x.setVisible(true);
    }
}


Second method is to use java.awt.Toolkit  to read the image :


import java.awt.*;
import java.io.*;
public class cFrame extends Frame {
Image img = null;

    public cFrame() {
        super();
        this.setSize(400, 400);
        this.setLocation(100, 100);
        this.setBackground(Color.green);
        this.setLayout(null);
        Toolkit t;
        t = java.awt.Toolkit.getDefaultToolkit();
        img = t.getImage("YourGifFile.gif");//you can use an URL too
        repaint();
    }

    public void update(Graphics g) {
        paint(g);
    }

    public void paint(Graphics g) {
        if(img!=null)
            g.drawImage(img, 0, 0, size().width, size().height, this);
    }    
    public static void main(String arg[]) {
        cFrame x = new cFrame();
        x.setVisible(true);
    }
}

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.