为什么这两个setColor不会冲突,反而可以一个颜色一个设背景
paint是怎么调用的
package com.qxp;
import javax.swing.*;
import javax.xml.crypto.Data;
import java.awt.*;
import java.util.Date;
public class Time extends JFrame implements Runnable {
Thread clock;
public Time()
{
super("Clock-CN");
this.setFont(new Font("Times New Roman", Font.BOLD, 60));
this.go();
this.setSize(280,100);
this.setVisible(true);
}
@Override
public void run() {
while(true)
{
repaint();
try {
Thread.sleep(1000);
}catch (InterruptedException e){}
}
}
public void go()
{
if (clock==null)
{
clock=new Thread(this);
clock.start();
}
}
public void stop()
{
clock=null;
}
public void paint(Graphics g)
{
String s="";
Date now = new Date();
int hour=now.getHours();
int minute=now.getMinutes();
int second=now.getSeconds();
s=hour+":"+minute+":"+second;
*** g.setColor(Color.WHITE);**
Dimension dim = getSize();
g.fillRect(0, 0, dim.width, dim.width);
** g.setColor(Color.BLACK);**
g.drawString(s,20 , 80);
}
public static void main(String[] args) {
Time that=new Time();
that.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
```