The image "Pic.jpg" is originally in "C:\Users\qwerty\Documents\NetBeansProjects\SelfTestX\src\Java\image"
.
It didn't work. I read up on getResource()
and it actually reads from where the .class files are stored at.
So, I copied the same image and pasted it at "C:\Users\qwerty\Documents\NetBeansProjects\SelfTestX\build\classes\Java\image"
It didn't work either.
Any help is greatly appreciated.
I listed the essential code below. Hopefully it is short enough.
public void setImage() throws IOException{
URL img=getClass().getResource("image/Penguins3.jpg");
BufferedImage bi=ImageIO.read(img);
int w=bi.getWidth();
int h=bi.getHeight();
int count=0;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
BufferedImage wi=bi.getSubimage(i*w/3,j*h/3, w/3, h/3);
Image sc=bi.getScaledInstance(puzpiece.getWidth()/3,
puzpiece.getHeight()/3, Image.SCALE_AREA_AVERAGING);
setupImage(count++,sc);
}
}
}
private void setupImage(int a,Image wi) {
button[a]=new JButton(new ImageIcon(wi));
}