I seem to be having an issue with Java Web Start not running my application correctly. When I run the code as an application (i.e. without web start) the following code results in the stopping of sound that is being played, and the halting of an animation.
if (evt.getSource() == stopButton)
{
if (clipPlayer != null)
{
//Stop the sound from playing
clipPlayer.stopPlaying();
}
for (int i = 0; i < rhythmWheel.NUM_WHEELS; i++)
{
rhythmWheel.getWheelPanels()[i].wheel.setRotationAngle(0);
}
//Stop the wheel from rotating.
paintTimer.stop();
}
However, when this code is run through web start, the sound stops playing, but the animation continues. I believe that this is caused by the Timer continuing to fire events, because removing the actionListener from the Timer results in the animation stopping even in w开发者_StackOverfloweb start.
How can I force the application to make the Timer stop firing events when run in Java Web Start?
I believe you have an uncaught exception in your code.
First of all, learn to invoke your JNLP file manually with javaws so you can see what is printed to the console. E.g. javaws foo.jnlp
.
If this isn't enough, then add print statements (or log statements if you use logging) so you can SEE that the final statement is actually reached.
Try
if (evt.getSource() == stopButton)
{
if (clipPlayer != null)
{
//Stop the sound from playing
clipPlayer.stopPlaying();
}
System.out.println("after stopPlaying(). rhythmWheel.NUM_WHEELS=" + rhythmWheel.NUM_WHEELS);
for (int i = 0; i < rhythmWheel.NUM_WHEELS; i++)
{
rhythmWheel.getWheelPanels()[i].wheel.setRotationAngle(0);
System.out.println("set " + i + " to 0");
}
//Stop the wheel from rotating.
paintTimer.stop();
System.out.println("stop() called");
}
If you see "stop() called" the timer should stop.
I'd like to know why this bug appears in the program when run under Java Web Start.
Verify that you are constructing the GUI on the event dispatch thread. This is required for Swing applets, too. java-web-start may be altering the timing just enough to expose the problem.
精彩评论