Tuesday 15 January 2013

java - Interrupting a thread doesn't work after pushing a (applet) button -



java - Interrupting a thread doesn't work after pushing a (applet) button -

i made simple programm allow java play .mp3 files. using jlayer right. problem can't interrupt player after pushing button.

my code in actionperformed:

class mythread extends thread { @override public void run() { seek { file file = new file(source); fileinputstream fis = new fileinputstream(file); bufferedinputstream bis = new bufferedinputstream(fis); seek { thread.sleep(1); seek { player player = new player(bis); player.play(); } grab (javalayerexception ex) { } } grab (interruptedexception e) { system.out.println("came"); } } grab (ioexception e) { lab2.settext("error, pathway correct?"); } } } mythread mythread = new mythread(); if (event.getsource() == input) { source = input.gettext(); source = source.replace("\\", "\\\\"); lab1.settext(source); } if (event.getsource() == but1) { mythread.start(); } if (event.getsource() == but2) { but2.setlabel("stop"); mythread.interrupt(); but2.setlabel("stopped"); } }

}

when add together mythread.interrupt(); straight behind interrupt works , scheme gives me "came" output. if utilize button called input, wont work.

seems player class doesnt have stop method, can seek advancedplayer:

http://www.javazoom.net/javalayer/docs/docs1.0/javazoom/jl/player/advanced/advancedplayer.html

and stop() method.

java multithreading applet interrupt

No comments:

Post a Comment