Adding image in JApplet

ImageIcon icon= new ImageIcon("a.gif");
JLabel jLabel1=new JLabel(icon);

I am a newbie to Java and I am facing a problem to add image in a panel in applet. My image is in the same folder. My applet is visible without any problem but only image is not displayed.


public void init() 
    URL imageURL = new URL(getDocumentBase(), "a.gif");
    Image image = getImage(imageURL);
    ImageIcon icon = new ImageIcon(image);
    // ...

The ImageIcon constructor that accepts a String presumes the string represents the path & file name of a File.

Only trusted applets can access a File, and then only on the client file-system (not the server). If this is an application resource, it should be on the server, and can be accessed by URL.

Note that the ImageIcon constructor will also accept an URL, rather than the Image used above. I just wanted to highlight that applets have an inbuilt method to obtain images.

Need Your Help

how to convert user defined data type to hashset c#

c# hashset

I have user defined type Items which inherits IList, ICollection, IEnumerable. How to convert this type to HashSet<Items>. I am using below snippet, is there any efficient way to this?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.