在 Java Web Start 中运行时,Swing Timer 不会停止触发事件
我似乎遇到了 Java Web Start 无法正确运行我的应用程序的问题。当我将代码作为应用程序运行时(即没有网络启动),以下代码会导致正在播放的声音停止,并停止动画。
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();
}
但是,当通过 web start 运行此代码时,声音会停止播放,但动画会继续。我相信这是由计时器继续触发事件引起的,因为从计时器中删除 actionListener 会导致动画停止,即使在 Web 启动时也是如此。
在 Java Web Start 中运行时,如何强制应用程序使计时器停止触发事件?
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 web start.
How can I force the application to make the Timer stop firing events when run in Java Web Start?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
验证您是否在事件调度线程。这对于 Swing 小程序也是必需的。 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.
我相信您的代码中有一个未捕获的异常。
首先,学习使用 javaws 手动调用 JNLP 文件,以便您可以看到控制台上打印的内容。例如
javaws foo.jnlp
。如果这还不够,请添加打印语句(如果使用日志记录,则添加日志语句),以便您可以看到实际达到了最终语句。
尝试一下,
如果您看到“stop() called”,则计时器应该停止。
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 you see "stop() called" the timer should stop.