Running JDK 1.6.0.29
Hello fellow JD's. I've bee programming in Java for quite some time now but have never created a Runnable JAR file (never had to). Anyways, I have created a simple GUI. It runs as expect in Eclipse, but when I Export to Runnable JAR file, my jpg file and wav file are not included within the JAR file and not sure why. They are both stored within my Java Project. Here's the code to my simple program, if needed :
[package BSPackage; import java.applet.Applet; import java.applet.AudioClip; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class BullshitButton extends JFrame implements ActionListener { //Create AudioClip object to play bullshit remarks! private AudioClip myAudioPlayer; private JPanel bullshitPanel; private JFrame bullshitFrame; private JButton bullshitButton; private JLabel bullshitButtonPic; private String fileName; /** * @param args */ public static void main(String[] args) { BullshitButton myBullshitButtonApp = new BullshitButton(); } public BullshitButton() { //Create JPanel bullshitPanel = new JPanel(); //Create JFrame bullshitFrame = new JFrame("Bullshit Button"); //Create JButton bullshitButton = new JButton("Click for Bullshit!"); //Create Image object bullshitButtonPic = new JLabel(new ImageIcon("bullshit button.jpg")); //add JPanel to Frame bullshitFrame.add(bullshitPanel); //add bullshit button pic to background bullshitPanel.add(bullshitButtonPic); //add ActionListener to button and then add to JPanel bullshitButton.addActionListener(this); bullshitPanel.add(bullshitButton); //Close running process by clicking the 'X' in the upper left corner bullshitFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set JFrame size bullshitFrame.setSize(265, 350); bullshitFrame.setVisible(true); } @Override public void actionPerformed(ActionEvent arg0) { playSoundFile(); } public void playSoundFile() { int determineSoundClip = 1; switch(determineSoundClip) { case 1: fileName = "This is Absolute Bullshit.wav"; break; case 2: fileName = ""; break; case 3: fileName = ""; break; case 4: fileName = ""; break; case 5: fileName = ""; break; default: determineSoundClip = 1; break; } determineSoundClip++; try { File file = new File(fileName); if(file.exists()) { myAudioPlayer = Applet.newAudioClip(new File(fileName).toURL()); } else throw new RuntimeException("Sound: " + fileName + " not found"); } catch(Exception e) { throw new RuntimeException("Sound: Bad Url: " + e); } myAudioPlayer.play(); } }
Here's what my GUI looks like when executed in Eclipse:
bullshitGUI.JPG
Then when executed with the exported Runnable Jar file, the bullshit button picture is gone and of course by clicking the button, no sound is being played.
Any thoughts or suggestions?