1 Replies - 262 Views - Last Post: 27 May 2011 - 07:32 AM Rate Topic: -----

#1 scopolamine  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 19
  • Joined: 10-April 11

Adding an image in applet

Posted 27 May 2011 - 07:25 AM

I moved icon.jpg to src directory. There is no compile error but I still can't see the icon.jpg in the applet. What did I do wrong?

import javax.swing.JApplet;
import javax.swing.ImageIcon;
import java.awt.Graphics;

public class RandomEraseImage extends JApplet
{
    private ImageIcon mapImage;
    public void init()
    {
        mapImage = new ImageIcon ("icon.jpg");
    }
    public void paint( Graphics g )
    {
        super.paint( g );
        mapImage.paintIcon( this, g, 0, 0);
    }
}



Okay, I figured out. Icon.jpg shouldn't be in the src file, it should be in the main directory.

Sorry for this topic.

Is This A Good Question/Topic? 1
  • +

Replies To: Adding an image in applet

#2 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Adding an image in applet

Posted 27 May 2011 - 07:32 AM

It's ok. I'm glad you posted your solution to the problem. Many many people have problems with putting outside files in the proper location for use
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1