是否可以随着时间的推移使JLabel的大小增加?我试着在for循环中使用thread.sleep(),但它不能正常工作。它只是等待了n秒钟,然后将JLabel粘贴到中
我使用的代码:
try {
for (int i = 0; i < 25; i++) {
label.setBounds(x, y, 125+(i*20), 125+(i*20));
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
提前谢谢。
您可以使用javax.swing.Timer
示例:
//1000 is the delay of each tick
timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(i == 2)
{
timer.stop();
}
label.setBounds(71, 194, 125+(i*20), 125+(i*20));
i++;
}
});
timer.start();