1
public Frame(String title) {
    setTitle(title);
     try{
          Clip crit = AudioSystem.getClip();
            AudioInputStream inputStream1 = AudioSystem.getAudioInputStream(this.getClass().getResource("k.wav"));
            crit.open(inputStream1);
            crit.loop(Clip.LOOP_CONTINUOUSLY);
     }        catch(Exception e){
            e.printStackTrace();
        }
    setContentPane(new JLabel(new ImageIcon(Frame.class.getClassLoader().getResource("img/lel.png"))));
    setVisible(true);
    setBounds(600,600,1024,833);
    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    this.setResizable(false);
    setLocationRelativeTo(null);
    addMouseListener(this);
}

I'm trying to figure out how to add the lel.png and k.wav to be inside of the JAR file to make my program work?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Cammy
  • 15
  • 6

1 Answers1

0

If you generate your jar file and put the resource files and the jar file in a folder structure like below, you can use relative paths.

myjar.jar data/ ---k.wav img/ ---lel.png

Ex:

try {//we need to catch UnsupportedAudioFileException
    AudioInputStream inputStream1 = AudioSystem.getAudioInputStream(new File("data/k.wav")); 
} catch (Exception e) {
        System.out.println(e);
}
shan1024
  • 1,389
  • 7
  • 17