How to get .gif picture in Java Frame?

Z

Zhao

Hi,
I made a Java program that I want to insert a .gif into my frame
window. It can be shown through appletviewer in the local machine, but
it can't be displayed from index.html.

insert into a frame window:
class frame1 extends Frame
{
Image picture = getToolkit().getImage("pic.gif");//pic.gif is on
current directory

public void paint (Graphics page)
{
page.drawImage (picture, 50, 100,200,50, this);

}//method paint()
}

Another applet class that can invoke the frame1 is embeded in a
index.html. When run the index.html, the picture is not displayed. Can
anybody tell me how to get the picture from index.html?
Thanks.

zhao
 
C

Chris Rehm

Zhao said:
insert into a frame window:
class frame1 extends Frame
{
Image picture = getToolkit().getImage("pic.gif");//pic.gif is on
current directory

I had been using this method without any problems for some jpg files but
recently I had a problem with it. For some reason, it would just fail to
finish loading my image. (1.4.2 under Windows XP). When I tried to print
the image using Graphics2D.drawImage(), the method was returning false.

I could not find any reason for this issue, and I switched to using:

Image picture;
try
{
picture = ImageIO.read(new File("picture.jpg"));
}

and it worked. I haven't changed all my code, so the places where I was
using getToolkit().getImage(); are still there and working for the
images I am loading with it.

I just thought I'd mention it in case the OP has a problem.

--
Chris Rehm
(e-mail address removed)

Thou shalt not avenge, nor bear any grudge against the children of thy
people, but shalt love thy neighbour as thyself. [Lev. 19:18]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top