java - How to run music in runnable jar file -



java - How to run music in runnable jar file -

how able run music in runnable jar file? programs runs music when compile , run code. when seek making runnable jar file through eclipse, not run music reason.

my code

import java.awt.color; import java.awt.font; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.border.lineborder; import sun.audio.*; import java.io.*; public class birthday { static jframe bday = new jframe(); static jpanel panel = new jpanel(null); public static void main(string[] args) { fillpanel(); bday.add(panel); panel.setfocusable(true); bday.setdefaultcloseoperation(jframe.exit_on_close);/ bday.setsize(325,250); bday.setlocationrelativeto(null); bday.settitle("happy birthday"); bday.setresizable(true); bday.setvisible(true); } public static void fillpanel(){ color fav = new color(50,190, 189); fav = generatepastelcolor(fav); panel.setbackground(fav); jlabel hb = new jlabel("happy birthday!!"); hb.setfont(new font("verdana", 2,30)); hb.setborder(new lineborder(color.white)); panel.add(hb); hb.setbounds(8, 50, 295, 50); jbutton button = new jbutton("click me"); panel.add(button); button.setbounds(50, 150, 200, 50); button.addactionlistener(new al()); } public static class al implements actionlistener{ public final void actionperformed(actionevent e){ music(); } } public static color generatepastelcolor(color mix) { int reddish = 50; int greenish = 190; int bluish = 189; // mix color if (mix != null) { reddish = (red + mix.getred()) / 2; greenish = (green + mix.getgreen()) / 2; bluish = (blue + mix.getblue()) / 2; } color color = new color(red, green, blue); homecoming color; } public static void music(){ audioplayer mgp = audioplayer.player; audiostream bgm; audiodata md; continuousaudiodatastream loop = null; seek { bgm = new audiostream(new fileinputstream(new file("music\\birthday.wav"))); md = bgm.getdata(); loop = new continuousaudiodatastream(md); } grab (ioexception e) { e.printstacktrace(); } mgp.start(loop); } }

file within jar file no longer file, alter read resource

bgm = new audiostream(new fileinputstream(new file("music\\birthday.wav")));

to

bgm = new audiostream(birthday.class.getresourceasstream ("/music/birthday.wav"));

assuming have music/birthday.wav @ root of classpath

java swing music embedded-resource executable-jar

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -