For some reason the following code is not importing the image correctly and displaying it. If I comment out the draw part it work. I can not figure out why.
import javax.swing.*;
import java.awt.*;
import java.net.URL;
public class BoardBuild extends JPanel{
String picPath = "pictures/";
String[] fileName = {"board.png"};
ClassLoader cl = BoardBuild.class.getClassLoader();
URL imgURL[] = new URL[1];
Toolkit tk = Toolkit.getDefaultToolkit();
Image imgBG;
public BoardBuild() throws Exception {
for (int x = 0; x < 1; x++)
imgURL[x] = cl.getResource(picPath + fileName[x]);
imgBG = tk.createImage(imgURL[0]);
}
public void paintComponent(Graphics g) {
g.drawImage(imgBG, 0, 0, 150,150 , 0, 0,73, 73, this);
}
}
As it is Eclipse, the pictures are in the folder workspace\BoardMaskTest\src\pictures.
I would appreciate the help.
Resources are taken from from the class path, looking with 7zip or Winzip in the jar one sees:
Furthermore the image can be loaded as