【发布时间】:2014-12-28 13:35:18
【问题描述】:
public class TestFrame extends JFrame
{
public TestFrame()
{
setBounds(10, 10, 500, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(3);
}
public static void main(String[] args) throws InterruptedException
{
TestFrame tf = new TestFrame();
tf.add(new JButton("test1"));
tf.setVisible(true);
Thread.sleep(2000);
tf.getContentPane().removeAll();
tf.add(new JButton("test2"));
System.out.print("Show test");
}
}
我希望程序在 2 秒后显示 JButton("test2")。
然后我在test1之后添加thread.sleep(2000)。
但我不知道为什么程序停止显示test1 JButton,
不显示 test2 JButton 并且“显示测试”消息可以成功打印出来
【问题讨论】:
-
这类问题在一周内会被问(并解决)好几次。您是否尝试过先寻找解决方案?
标签: java multithreading swing