954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

diplaying .gif image in JApplet

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"

MastaPho
Newbie Poster
3 posts since Aug 2005
Reputation Points: 10
Solved Threads: 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.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

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.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You