I've tried doing this before, except with image files for my software engineering class. It's really a pain in the ar$e, imo.
I had to right click on my project folder then
New>Source Folder>bin
I chose the bin folder and clicked ok.
It should add another package/folder looking image in your folder structure.
Then, I had to manually add the image inside of the bin folder. In my case, I just didn't want to drop them right into the bin folder, so I had another folder inside of bin called images.
Note*** You have to add the files into both folders, bin and images. (In my case)
To load the image, you'll have to use the this.getClass().getResource("filename.wav"); method.
Here is the very simple code I used as an example:
public class JarRunner {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane( new MyJPanel() );
frame.pack();
frame.setVisible(true);
}
}
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MyJPanel extends JPanel {
public MyJPanel() {
ImageIcon imageIcon = new ImageIcon(getClass().getResource("exampleImage.jpg"));
JLabel label = new JLabel( imageIcon );
this.add(label);
}
public Dimension getPreferredSize() {
return new Dimension( 200, 200 );
}
}
Here is the screenshot of the folder/file structure and bin folder.
jarTest.png 142.11K
70 downloads
Hopefully it works the same for audio files.