代码如下,请问该如何在java awt中让字体出现之后几秒消失,求大神解答!

final JLabel j1;
j1 = new JLabel();
add(j1);
setVisible(true);
Thread t = new Thread(new Runnable() {
@Override
public void run(){
Color color = g.getColor();
g.setColor(Color.blue);
j1.setText("哥?还在不?干嘛呢");
g.setColor(color);
try {
Thread.sleep(5000);
}catch (InterruptedException ex) {
}
j1.setText("");
}
});
t.start();
}

Cats萌萌
浏览 161回答 2
2回答

拉莫斯之舞

线程中,不要直接访问界面的组件,通过自定义事件

qq_花开花谢_0

j1.setText(""") 后再加上j1.repaint();试试看。
打开App,查看更多内容
随时随地看视频慕课网APP