While循环使小程序白屏且无响应 [英] While loop makes applet white screen and unresponsive

查看:182
本文介绍了While循环使小程序白屏且无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的循环代码(这是与我的循环有关的唯一代码):

Here is my loop code (This is the only code relating to my loop):

while(true)
    {
        try {
            Thread.sleep(20);
            System.out.println("1");
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }           
    }

启动小程序时,它会变成白色屏幕,除非按下Eclipse中的终止"按钮,否则无法将其关闭.

When I launch the applet, it white screens and I cannot close it unless I press the "Terminate" button in eclipse.

推荐答案

您正在使用无限的while循环来阻止UI线程.您没有说使用的是AWT还是Swing小程序,无论哪种方式,结果都是相同的.如果您使用的是Swing小程序,请使用 Swing Timer .如果您使用的是旧的重量级AWT,请将其转换为Swing并遵循以前的建议.

You're blocking the UI Thread with an infinite while loop. You don't say whether you're using an AWT or Swing applet, either way the result will be the same. If you're using a Swing applet, use a Swing Timer. If you're using the old heavyweight AWT, convert it to Swing and follow the previous advice.

这篇关于While循环使小程序白屏且无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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