currently using JBuilder Foundations
task is to display a .gif file in JApplet from my hardrive
the URL is C:\MAGIX
Should the image file be located elsewhere in a specific place?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class Applet1 extends JApplet {

    public void init(){
        Container contentPane=getContentPane();
        ImageIcon icon=new ImageIcon("icon.gif");
        JLabel jl=new JLabel("icon",icon,JLabel.CENTER);
        contentPane.add(jl);
    }
}

when running the JApplet, only prints "icon"

applet security restrictions prevent you from reading anything from your harddrive.
You can only read files from network addresses on the same server (or more correctly (virtual) host) as the one where the applet resides.
As the applet is in your case not coming from a server it can't read anything at all.
Maybe if you place the applet and file in the same directory you can access it, but that would be due to VM specific laxness rather than official policy.

I've never dealt with icons on an applet, but whenever I wanted to draw an image onto the applet I never had a problem if I put it in the same file. Why don't you check the java console and see if it's a security restriction or if it's a FileNotFoundException.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.