2013-06-26 25 views
1

我正在为我的朋友做一个基本的程序,显示他的这个有趣的图片并循环播放声音。当我导出我的JAR它没有工作,所以我打开了JAR用WinRAR和文件都在那里,但他们并没有打如何将图像和声音导出到我的可运行jar包中?

CODE:

//imports 
public class twerk { 
static File fl = new File("res//sounds//liver.au"); 
static int loo = 1; 
static JFrame frame = new JFrame("COLLIN"); 
public static void frame(){ 
    frame.setSize(1086,800); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setResizable(false); 
    ImageIcon image = new ImageIcon("res//images//collin.jpg"); 
    JLabel label = new JLabel(image); 
    frame.add(label, BorderLayout.NORTH); 
    frame.setIconImage(image.getImage()); 
    frame.setVisible(true); 
    try 
    { 

     String st =fl.getPath(); 
     InputStream in = new FileInputStream(st); 
     AudioStream au = new AudioStream(in); 
     AudioPlayer.player.start(au); 
     if(loo == 1){ 
      Thread.sleep(1900); 
      frame(); 
     } 

    } catch(Exception e){} 
} 
    public static void main(String[] args){ 


    frame(); 

} 

} 

JAR文件的图片在WinRAR打开

enter image description here

所以你可以看到,图像和声音文件夹是jar文件,但他们没有被使用

回答

2

到部署时,这些资源已成为。既然如此,资源必须由URL而不是File访问。有关标签,请参阅info page,以形成URL

注意路径。根据该清单:

"res//images//collin.jpg" 

应该改为:

"/images/collin.jpg" 
相关问题