我在JPanel面板试这样实现的,是用定时器实现的,实现过程如下:
protected void paintComponent(Graphics g) {
// draw the current time as the text
g.setColor(Color.BLACK);
g.drawString(hour + ":" + minute + ":" + second, 10, 15);
}定时器事件函数如下:
public void actionPerformed(ActionEvent e) {
setCurrentTime();
repaint();
}我想实现动态显示时间 格式是这样的 23:27:01
可是我的运行的时候 比如说一开始为 20:27:01 后来为20:27:02 他们重叠了 。
我试着去擦除原来的数字,可是还是不行。请问如何来擦除原来的数字啊?或者有什么更好的解决方法?求大家帮下忙!谢谢!
protected void paintComponent(Graphics g) {
// draw the current time as the text
g.setColor(Color.BLACK);
g.drawString(hour + ":" + minute + ":" + second, 10, 15);
}定时器事件函数如下:
public void actionPerformed(ActionEvent e) {
setCurrentTime();
repaint();
}我想实现动态显示时间 格式是这样的 23:27:01
可是我的运行的时候 比如说一开始为 20:27:01 后来为20:27:02 他们重叠了 。
我试着去擦除原来的数字,可是还是不行。请问如何来擦除原来的数字啊?或者有什么更好的解决方法?求大家帮下忙!谢谢!
if (ui != null) {
Graphics scratchGraphics = (g == null) ? null : g.create();
try {
ui.update(scratchGraphics, this);
} finally {
scratchGraphics.dispose();
}
}
}
找到代码了 ,发来给大家共享下