Picture not showing when create JAR file
When I run the below code from the console or in Eclipse it run perfect with the "logo.jpg" showing in the center of my screen.
When I extract it into a JAR File and them try to run it. It seem like it can't find the picture. I can't figure out what I'm doing wrong.
Code:
class LogoFlashScreen {
String logo = "logo.jpg";
Toolkit toolkit;
int logoWidth;
int logoHeight;
int x;
int y;
public void runFlashScreen() {
JWindow flashWindow = new JWindow();
LogoPanel logoPanel = new LogoPanel();
flashWindow.add(logoPanel);
getLogoSizeAndLocation();
flashWindow.setSize(logoWidth, logoHeight);
flashWindow.setLocation(x, y);
flashWindow.setVisible(true);
for (int i=0; i<50; i++) {
try {
Thread.sleep(20);
}catch(Exception ex) {
}
}
flashWindow.setVisible(false);
}
public void getLogoSizeAndLocation() {
logoWidth = new ImageIcon(logo).getIconWidth();
logoHeight = new ImageIcon(logo).getIconHeight();
toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
x = (int) (screenSize.getWidth() - logoWidth)/2;
y = (int) (screenSize.getHeight() - logoHeight)/2;
}
@SuppressWarnings("serial")
class LogoPanel extends JPanel {
public void paintComponent(Graphics g) {
Image image = new ImageIcon(logo).getImage();
g.drawImage(image,0,0,this);
}
}
}