<bdo id='jy1Ng'></bdo><ul id='jy1Ng'></ul>

  • <i id='jy1Ng'><tr id='jy1Ng'><dt id='jy1Ng'><q id='jy1Ng'><span id='jy1Ng'><b id='jy1Ng'><form id='jy1Ng'><ins id='jy1Ng'></ins><ul id='jy1Ng'></ul><sub id='jy1Ng'></sub></form><legend id='jy1Ng'></legend><bdo id='jy1Ng'><pre id='jy1Ng'><center id='jy1Ng'></center></pre></bdo></b><th id='jy1Ng'></th></span></q></dt></tr></i><div id='jy1Ng'><tfoot id='jy1Ng'></tfoot><dl id='jy1Ng'><fieldset id='jy1Ng'></fieldset></dl></div>

    <tfoot id='jy1Ng'></tfoot>

      <legend id='jy1Ng'><style id='jy1Ng'><dir id='jy1Ng'><q id='jy1Ng'></q></dir></style></legend>

      1. <small id='jy1Ng'></small><noframes id='jy1Ng'>

      2. 程序运行时如何播放背景音乐?在java中

        时间:2023-09-27
          • <bdo id='n8jjj'></bdo><ul id='n8jjj'></ul>

              <small id='n8jjj'></small><noframes id='n8jjj'>

                <tfoot id='n8jjj'></tfoot>
                  <legend id='n8jjj'><style id='n8jjj'><dir id='n8jjj'><q id='n8jjj'></q></dir></style></legend>
                    <tbody id='n8jjj'></tbody>

                  <i id='n8jjj'><tr id='n8jjj'><dt id='n8jjj'><q id='n8jjj'><span id='n8jjj'><b id='n8jjj'><form id='n8jjj'><ins id='n8jjj'></ins><ul id='n8jjj'></ul><sub id='n8jjj'></sub></form><legend id='n8jjj'></legend><bdo id='n8jjj'><pre id='n8jjj'><center id='n8jjj'></center></pre></bdo></b><th id='n8jjj'></th></span></q></dt></tr></i><div id='n8jjj'><tfoot id='n8jjj'></tfoot><dl id='n8jjj'><fieldset id='n8jjj'></fieldset></dl></div>
                  本文介绍了程序运行时如何播放背景音乐?在java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在制作一款纸牌游戏,并且快完成了.我想做的最后一件事是播放一些背景音乐.现在如果我将文件复制到默认包中并制作一个游戏的jar文件,音乐会在所有计算机上播放吗?目前,在我的 PC 上,通过为文件提供特定路径(如 "C:\samp.wav";),它可以毫无问题地运行.但我担心如果我制作一个 jar 文件并在另一台 PC 上运行它,它将无法正常工作.我想会有一个FileNotFoundException.我是对还是错?

                  I am making a card game, and it's almost done. The last thing I want to do is play some background music. Now if I copy the file into the default package and make a single jar file of the game, will the music play on all computers? Currently, on my PC it's running without any problem by giving a specific path for the file like "C:\samp.wav";. But I am worried that if I make a jar file and run it on another PC it won't work properly. I think there will be a FileNotFoundException. Am I right or wrong?

                  对于卡片的图像,我使用这一行:

                  For the card's image I am using this line:

                  jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/1.jpg")));
                  

                  我已经插入到我的默认包中的那些图片.我想对音乐文件做同样的事情,但是怎么做呢?我正在使用 NetBeans.

                  Those pictures I have inserted into my default package. I want to do the same for the music file, but how? I am using NetBeans.

                  推荐答案

                  您应该在应用程序 jar 中包含 wav 文件.这样您就不必管理用户文件系统中的文件副本(请记住,例如,在 UNIX、Mac 等中,您无法通过 C 访问硬盘驱动器:/...).

                  You should include the wav file inside your application jar. This way you won't have to manage the copy of the file in the user's file system (keep in mind that, for example, in UNIX, Mac, etc. you can't access to the hard drive through C:/...).

                  例如,如果您将 wav 文件放在 app jar 的根目录中(app.jar/samp.wav):

                  For example, if you place the wav file in the root of the app jar (app.jar/samp.wav):

                  InputStream is = getClass().getClassLoader().getResourceAsStream("samp.wav");
                  

                  或者,如果您在应用 jar 根目录中有声音"目录 (app.jar/sounds/samp.wav):

                  or, if you had a "sounds" directory in the app jar root (app.jar/sounds/samp.wav):

                  InputStream is = getClass().getClassLoader().getResourceAsStream("sounds/samp.wav");
                  

                  查看这篇文章了解更多关于使用 wav 文件播放的信息Java(尽管对于您的问题,我认为您已经解决了这个问题).考虑在单独的线程中播放它.另请查看此网站以获取有关使用 Java 管理媒体文件的示例.

                  Check this post for extra information about playing wav files with Java (though for your question, I think you have already solved this problem). Consider as well playing it in a separate thread. Check also this web for examples about managing media files in Java.

                  这篇关于程序运行时如何播放背景音乐?在java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:这是 Java 包导入应该如何工作的吗? 下一篇:struts.xml 中 Struts 的默认包名是什么?

                  相关文章

                  最新文章

                  <tfoot id='hCEA5'></tfoot>

                    <small id='hCEA5'></small><noframes id='hCEA5'>

                    <i id='hCEA5'><tr id='hCEA5'><dt id='hCEA5'><q id='hCEA5'><span id='hCEA5'><b id='hCEA5'><form id='hCEA5'><ins id='hCEA5'></ins><ul id='hCEA5'></ul><sub id='hCEA5'></sub></form><legend id='hCEA5'></legend><bdo id='hCEA5'><pre id='hCEA5'><center id='hCEA5'></center></pre></bdo></b><th id='hCEA5'></th></span></q></dt></tr></i><div id='hCEA5'><tfoot id='hCEA5'></tfoot><dl id='hCEA5'><fieldset id='hCEA5'></fieldset></dl></div>
                  1. <legend id='hCEA5'><style id='hCEA5'><dir id='hCEA5'><q id='hCEA5'></q></dir></style></legend>
                        <bdo id='hCEA5'></bdo><ul id='hCEA5'></ul>