程序怎么改?
import java.awt.*;import java.applet.*;
import java.util.Date;
public class Clock extends Applet implements Runnable
{
Thread clockThread;
Font font;
public void init()
{
font =new Font("TimesRoman",Font.BOLD,48);
}
public void start()
{
if(clockThread==null)
{
clockThread=new Thread(this,"Showtime");
clockThread.start();
}
}
public void run()
{
while(clockThread!=null)
{
repaint();
try
{
clockThread.sleep(1000);
}catch(InterruptedException e) { }
}
}
public void paint(Graphics g)
{
Calendar now =new Calendar()
g.setFont(font);
g.setColor(Color.red);
g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,50);
}
public void stop()
{
}
}
编译结果:
D:\xu>javac Clock.java
Note: Clock.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
初步了解Date类的getHours(),getMinutes() getSeconds(),不能用了,
那该如何获取时间?