如何杀死的Java小程序在一个循环beeing关闭浏览器时? [英] How to kill Java-Applet beeing in a loop when browser is closed?

查看:171
本文介绍了如何杀死的Java小程序在一个循环beeing关闭浏览器时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java小程序来显示图像。我为了permantly接收通过TCP / IP套接字的新形象在paint()方法,而一个真正的循环。现在我有问题,该应用程序仍然是从服务器请求新的图像,即使在关闭标签。我该如何解决呢?

I have a Java Applet to show images. I have a while true loop in paint() in order to permantly receive new images via tcp/ip socket. Now I have the problem, that the app is still requesting new Images from the server, even when the tab is closed. How can I fix that?

推荐答案

只是要清楚:

我在 A ,而(真)循环的paint()为了永久接收通过TCP新形象/ IP套接字。

I have a while(true) loop in paint() in order to permanently receive new images via tcp/ip socket.

不要这样做。 paint方法不应该阻止一个较长的时间框架。它不应该的只有的画你的图片,没有别的。 (只要paint方法运行,其他什么都在你的GUI可以做任何事情。这可能不是你的小应用程序的关键,但是这将是更复杂的程序。)

Don't do this. The paint method should never block for a longer time frame. It should only paint your images, nothing else. (As long as the paint method is running, nothing else in your GUI can do anything. This may not be critical for your applet, but it will be for more complicated programs.)

如果您需要加载新的图像,在一个单独的线程做到这一点,把图像中的变量,并调用重绘()结尾。然后paint方法从变量取图像,并将其绘制到屏幕上。

If you need to load new images, do this in a separate thread, put the image in a variable, and call repaint() at the end. The paint method then takes the image from the variable and draws it to the screen.

这篇关于如何杀死的Java小程序在一个循环beeing关闭浏览器时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆