1 Replies - 3408 Views - Last Post: 15 February 2010 - 05:21 PM Rate Topic: -----

#1 Jude Nash  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 98
  • Joined: 25-October 08

Put image in Applet

Posted 15 February 2010 - 03:55 PM

Hello programmers,
I am trying to make an image show in an applet. It compiles, loads, but doesn't show the image.
Please help,
Jude Nash

 import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
 
public class imagePractice extends Applet
{
        public void init()
        {
             
        }
        public void paint(Graphics g)
        {
			ImageIcon img = new ImageIcon("bi.gif");
			Image image = img.getImage();
			g.drawImage(image,100,100,this);
        }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Put image in Applet

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Put image in Applet

Posted 15 February 2010 - 05:21 PM

Applet usually do not access the file system so you have to do something like that

URL url = getCodeBase();
URL imageUrl = new URL(url.toString() + "bi.gif"));
or depending of your URL format
URL imageUrl = new URL(url.toString() + "/bi.gif"));

ImageIcon = new ImageIcon(imageUrl);

Also perform all these operations in your init() method no need to re-read from the disk every time you need to repaint
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1