Monday 15 April 2013

java - I Want To Make Audio Stop With A JButton, How Would I Do This? -


I want to stop the audio stream using a JButton , how can I do this ?

Here is my code:

  import sun.audio.AudioPlayer; Import sun Audio. Audio stream; Import javax.swing *; Import java.awt. *; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; Import java.io.file; Import java.io.FileInputStream; Import java.io.InputStream; Public class twerk {thread thread; Steady int = 1; Fixed file fl = new file ("MYFILE"); Public Static Zero Frame () {Jeffre Frame = New Gefram ("Colin"); Frame.setSize (1086800); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.setResizable (wrong); Image Image = New Imagens ("Mapper"); Jlabel label = new jlab (image); Frame.add (label, border layout. North); Frame.setIconImage (image.getImage ()); Pocket button = new pocket ("close sound"); Frame Add (Button, Border Layout. SOTH); Frame.setVisible (true); } Public Static Zero PlayClip () {try {string string = fl.getPath ()} InputStream = New FileInputStream (st); Audiostream au = new audio stream (in); AudioPlayer.player.start (AU); If (loo == 1) {Thread. Sleep (1900); PlayClip (); }} Hold (exception e) {}} public static zero main (string [] args) {frame (); PlayClip (); }}   

I want to stop the au with an actionlistener like this:

  Implementation of stable class action ActionListener {Public Zero Action Accredited ( ActionEvent e) {AudioPlayer .player.stop (); }   

How can I do something I can do something like this

  if (thinkton click) {audiostream.player.stop}   

Any input will be greatly appreciated!

Try implementing ActionListener in your Twerk class then execute the action method in your class and Add the listener to the button. For example

  public class twerk implementation {public void twerk () {button.addActionListener (this); // omitted} Public Zero Apocalypse (Action E) [Jebton TMP = (Jebtton) E. Getsource (); If (tmp == button) au.player.stop (); }   

And this is also a good practice to start with the names of your class with upper case letters such as 'Twerk'

Good luck with your application!

No comments:

Post a Comment