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
和「顯示測試」消息可以sucess打印出來
這類問題在一週內被問及(並解決了好幾次)。您是否嘗試過首先搜索解決方案? – Tom 2014-11-01 10:22:07