why is my japplet displays gray block in browser after adding an image icon?

141 Views Asked by At

My japplet is able to run normally in NetBeans environment, but shows only a gray block screen in my browser (Chrome, IE). But when I removed all the image icons from my japplet, it runs normally in the browser and I have totally no idea why. Need some guidance for this.

My japplet class content

public void init() 
{
    try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); }

    catch(Exception ex) { System.out.println(ex); }       

    try 
    {
        java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } });
    } 
    catch (Exception ex) { ex.printStackTrace(); }

    jlbReg.setIcon(new ImageIcon(getClass().getResource("/MyIcons/icon1.png"))); 
    jlbAnn.setIcon(new ImageIcon(getClass().getResource("/MyIcons/icon2.png")));
    jlbSubmit.setIcon(new ImageIcon(getClass().getResource("/MyIcons/icon3.png")));
    jlbForum.setIcon(new ImageIcon(getClass().getResource("/MyIcons/icon4.png")));
}

My html content

<APPLET codebase="classes" code="MyJApplet.class" width=1150  height=1000></APPLET>
1

There are 1 best solutions below

4
On

Your applet can't find the images in the jar file. Wait a minute - that's because you're not using a jar file. You need to use a jar file.