当我使用 JavaFX 时,睡眠功能不会相应地工作。就像在这段代码中:
public class Controller {
@FXML private Label label;
@FXML private Button b1;
public void write() throws InterruptedException
{
label.setText("FIRST TIME");
for(int i=1;i<=5;i++)
{
System.out.println("Value "+i);
label.setText("Value "+i);
Thread.sleep(2000);
}
label.setText("LAST TIME");
}
Run Code Online (Sandbox Code Playgroud)
当按下按钮 b1 时,将调用写入函数。现在,在 2 秒后在控制台中打印“Value + i”。但是那个时候标签 l1 的文本没有改变,最后它只变成了“LAST TIME”。这里有什么问题?