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);
}
我正在尝试弄清楚如何在JAR文件中添加lel.png和k.wav来使我的程序工作?
发布于 2015-09-12 04:43:34
如果生成jar文件,并将资源文件和jar文件放在如下所示的文件夹结构中,则可以使用相对路径。
myjar.jar data/ ---k.wav img/ ---lel.png
例如:
try {//we need to catch UnsupportedAudioFileException
AudioInputStream inputStream1 = AudioSystem.getAudioInputStream(new File("data/k.wav"));
} catch (Exception e) {
System.out.println(e);
}
https://stackoverflow.com/questions/32534817
复制相似问题