0

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"

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by server_crash
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.