user1950221
user1950221

Reputation: 13

Applet doesn't want to open in browser

My applet doesn't want to open in browser. I think that all is because of graphics.

I load it like this:

icon = new ImageIcon(getClass().getResource("logo.png"));

and use like this:

logo = new JLabel(icon);

Without graphics, everything is okay.

Upvotes: 0

Views: 106

Answers (1)

user1134181
user1134181

Reputation:

Use class loader to find images that are bundled in the jar file.

ClassLoader classLoader = this.getClass().getClassLoader();

URL imageURL = classLoader.getResource("images/icon.logo");
JLabel logo = new JLabel(new ImageIcon(imageURL));

See also:


Update

 +Project
 |
 |   
 +-src
 |  |
 |  |   
 |  +path
 |  |
 |  |-TargetClass.java
 |  ...
 |
 +-resources
 |  |
 |  |
 |  +-images       
 |  |    |
 |  ...  |-icon.logo
 ...     ...  

Upvotes: 1

Related Questions