I'm having massive issues packaging my java program which contains images into a jar for conversion into and executable file. The images have been used in the background of the program and buttons. Please see the diagram below which shows the program I desire to convert to a jar.
IMAGE
As you see above the program runs OK. I created the same program with no custom background and custom buttons containing no images and I successfully packaged it into a jar and subsequently into an .exe file.
With regards to drawing my background I'm doing this as follows:
public void paintComponent(Graphics g) {
Image img = new ImageIcon("imgs/Bgnd1.jpg").getImage();
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
g.drawImage(img, 0, 0, null);
}
With regards to creating my 4 custom buttons with images, I'm doing the following:
// Prepare rollover images
ImageIcon F1 = new ImageIcon("imgs/btn_f1_not_selected.jpg");
ImageIcon F1rollOver = new ImageIcon("imgs/btn_f1_selected.jpg");
// Create F1 button
final JButton btnF1 = new JButton(F1);
//btnF1.setOpaque(false);
btnF1.setContentAreaFilled(false);
btnF1.setBorder(null);
btnF1.setBorderPainted(false);
btnF1.setFocusPainted(false);
btnF1.setRolloverIcon(F1rollOver);
I attempted placing the images in the bin folder and for the creation of the background I altered the above method with regards to the declaration/fetching of the image.
public void paintComponent(Graphics g) {
String path = "Bgnd11.jpg";
java.net.URL imgURL = getClass().getResource(path);
Image img = new ImageIcon(imgURL).getImage();
Dimension size = new Dimension(img.getWidth(observer), img.getHeight(observer));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
g.drawImage(img, 0, 0, null);
}
I also attempted fetching the images needed for the creation of my buttons as indicated below and then passing them to my button but this did not work.
String path = "Bgnd11.jpg";
java.net.URL imgURL = getClass().getResource(path);
Image img = new ImageIcon(imgURL).getImage();
How to locate & load the images?