public class Clock extends java.applet.Applet implements Runnable
{
Thread clockThread;
public void start()//该方法是Applet的方法,不是线程的方法
{
if(clockThread == null)
{
clockThread = new Thread(this, "Clock");
clockThread.start();
}
}
public void run()
{
while (clockThread != null)
{
repaint();
try
{
clockThread.sleep(1000);
}
catch(InterruptedException e)
{}
}
}
public void paint(Graphics g)
{
Date now = new Date();
g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,10);
}
public void stop()
{
clockThread.stop();
clockThread = null;
}
}编译后
note:Clock.java uses or overrides a deprecated API.
note:Recompile with -Xlint:deprecation for details.
{
Thread clockThread;
public void start()//该方法是Applet的方法,不是线程的方法
{
if(clockThread == null)
{
clockThread = new Thread(this, "Clock");
clockThread.start();
}
}
public void run()
{
while (clockThread != null)
{
repaint();
try
{
clockThread.sleep(1000);
}
catch(InterruptedException e)
{}
}
}
public void paint(Graphics g)
{
Date now = new Date();
g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,10);
}
public void stop()
{
clockThread.stop();
clockThread = null;
}
}编译后
note:Clock.java uses or overrides a deprecated API.
note:Recompile with -Xlint:deprecation for details.
解决方案 »
- java HttpClient模拟登陆知乎问答网站,获取不到cookie
- ftpClient.storeUniqueFile 上传文件失败返回false 求高人指点!!
- windows xp中,如何把一大堆jar文件 快速加载到classpath变量中,
- 系统时间问题,怎么就设置不对呢?
- Tomcat启动时的问题
- 请教一个关于RSA加解密算法的问题。
- 身份证的验证
- 怎样用程序输出如下字符串 hello "|" word 也即字符串hello和word中间加入"|"
- package与import的问题
- 请班竹回答个问题。。。谢谢!
- 这样用有什么好处吗
- 谁教我内部类匿名的使用,从基础开始.又需要我等下在开个空问题付给100分给你....
提倡使用GregorianCalendar类;
paint()里改成:GregorianCalendar gc = new GregorianCalendar();
g.drawString(gc.get(Calendar.HOUR)+":"+gc.get(Calendar.MINUTE)+":"+gc.get(Calendar.SECOND),5,10);
但还是不行啊.
除了把:Date now = new Date();
g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,10);
改成:GregorianCalendar gc = new GregorianCalendar();
g.drawString(gc.get(Calendar.HOUR)+":"+gc.get(Calendar.MINUTE)+":"+gc.get(Calendar.SECOND),5,10);还要改其他地方吗?
但还是编译不了.换了你的那部分之后.
6个错误.
cannot find symbol
symbol:class GregorianCalendercannot find symbol
symbol:class variable Calendarcannot find symbol
symbol:variable g...note:Clock.java uses or overrides a deprecated API.
note:Recompile with -Xlint:deprecation for details.(依然有这个)
import java.awt.event.*;
import java.awt.Graphics;
import java.applet.Applet;
import java.io.*;
import java.applet.*;
import java.lang.*;请问要import哪些包呢?我import后还是老问题啊.
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;