I have made a Java Applet.
<applet code=gui.clientGUI.MyApplet.class
archive="QTminer.jar"
width=400 height=200>
</applet>
my jar looks like this:
this is my simple code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
public class MyApplet extends JApplet {
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
initUI();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
private void initUI() {
getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
JButton btnStartApplication = new JButton("Start Application");
btnStartApplication.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SS oi = new SS();
oi.setVisible(true);
}
});
getContentPane().add(btnStartApplication);
}
}
class SS extends JWindow {
private JLabel lblNewLabel;
private JLabel label;
public SS() {
setBounds(new Rectangle(0, 0, 883, 590));
setLocationRelativeTo(null);
getContentPane().setLayout(null);
lblNewLabel = new JLabel("Welcome", SwingConstants.CENTER);
lblNewLabel.setForeground(Color.RED);
lblNewLabel.setFont(new Font("Segoe UI", Font.BOLD | Font.ITALIC, 24));
lblNewLabel.setBounds(0, 313, 883, 41);
getContentPane().add(lblNewLabel);
label = new JLabel(new ImageIcon(getClass().getResource("/gui/resources/Qtminer_background.jpg")));
label.setBounds(0, 0, 883, 592);
getContentPane().add(label);
setVisible(true);
}
}
My problem is that when running in eclipse everything works, but when running in browser i get a NullPointerException right on the load of the image icon:
label.setIcon(new ImageIcon(getClass().getResource("/gui/resources/Qtminer_background.jpg")));