I want to stop the audio stream using a Here is my code: I want to stop the au with an actionlistener like this: How can I do something I can do something like this 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 And this is also a good practice to start with the names of your class with upper case letters such as Good luck with your application! JButton , how can I do this ?
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 (); }}
Implementation of stable class action ActionListener {Public Zero Action Accredited ( ActionEvent e) {AudioPlayer .player.stop (); }
if (thinkton click) {audiostream.player.stop}
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 (); }
'Twerk'
No comments:
Post a Comment