我创建了一个扩展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();
关于java - 使用 Thread.sleep 时 JApplet 内容会被清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27576846/