954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Sound to button

Hello World!

Im doing a simple program that runs a JFrame and has some JButtons etc etc but id like to put a simple sound to one of my buttons, when i quit the program i want it to play a simple melody how can i put it in this simple button? this is where id like to put it but i cant find how to put in in there:

public class quitHandler implements ActionListener{
		public void actionPerformed(ActionEvent ae){
		/*here i guess i should put some kind of method or something*/	
                System.exit(0);
		}
	}
scripter_tmrage
Newbie Poster
12 posts since Jul 2009
Reputation Points: 6
Solved Threads: 0
 

There are a couple of ways to play a simple sound in Java. This explains the newer. better (but harder) way:
http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml
and this is the older, simpler,way:
http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java

Either way, you call the appropriate code from your actionPerformed method.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

I'll check them out thanks a lot =)

scripter_tmrage
Newbie Poster
12 posts since Jul 2009
Reputation Points: 6
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: