Problem with loading a PNG image in JApplet.

Posted by Bruce on Stack Overflow See other posts from Stack Overflow or by Bruce
Published on 2010-04-08T14:50:44Z Indexed on 2010/04/08 14:53 UTC
Read the original article Hit count: 240

Filed under:
|
|
|

Hi there,

I'm trying to load a PNG image from JAR file when running JApplet. The file is, I think, loaded properly - there are no errors. However it is not displayed. img.png is placed in the same directory as MainClass.java file. Here is the code:

InputStream       imageURL = this.getClass().getResourceAsStream("img.png" );
    byte[] bytes = null;
    try {bytes = new byte[imageURL.available()];
    System.out.println(imageURL.available());
    imageURL.read(bytes);}
    catch(Exception e) {System.out.println("bleah");}

    Image     image       = Toolkit.getDefaultToolkit().createImage(bytes);
    Image     imageScaled = me.getScaledInstance( 100, 150, Image.SCALE_SMOOTH );

jLabel6 = new javax.swing.JLabel( new ImageIcon( imageScaled) );

and the HTML exerpt:

<APPLET codebase="classes" code="myapplet/MainClass.class" archive ="LittleApplet.jar" width=700 height=500>

The image, as I wrote, is probably read, but not displayed in JLabel.

What am I missing/doing wrong?

Thanks in advance for the reply!

© Stack Overflow or respective owner

Related posts about image

Related posts about png