Java 当使用Thread.sleep时,JApplet内容将被清除

Java 当使用Thread.sleep时,JApplet内容将被清除,java,Java,我创建了一个扩展JApplet的类。当我试着去做 while(whichButtonChosen==null){ try{ Thread.sleep(1); }catch(InterruptedException e){ e.printStackTrace(); } 小程序的内容将消失 必须将此循环放入线程中。如果您像现在这样在GUI线程上运行它,GUI将不会绘制它的组件(因为它在循环中变得繁忙),并且看起来是空的 new Thread(new Runnable() {

我创建了一个扩展
JApplet
的类。当我试着去做

while(whichButtonChosen==null){
try{
Thread.sleep(1);
}catch(InterruptedException e){
e.printStackTrace();
}

小程序的内容将消失

必须将此循环放入线程中。如果您像现在这样在GUI线程上运行它,GUI将不会绘制它的组件(因为它在循环中变得繁忙),并且看起来是空的

 new Thread(new Runnable() {

                @Override
                public void run() {
    while(whichButtonChosen==null){
    try{
    Thread.sleep(1);
    }catch(InterruptedException e){
    e.printStackTrace();
    }

                }
            }).start();

这个while循环是否在线程内?不,它不是在线程内。