我用线程序写了一个时间程序,想用父类的drawstring方法将其输入到面板上,怎样调用?希望详细一点如drawstring(s,1,1),要求不断重写s来动态显示时间程序如下,不知道怎么一直重写s:...
我用线程序写了一个时间程序,想用父类的drawstring 方法将其输入到面板上,怎样调用?希望详细一点
如drawstring(s,1,1),要求不断重写s来动态显示时间
程序如下,不知道怎么一直重写s:
class DesktopPane extends JDesktopPane implements Runnable
{
Thread tr;
String s="";
public void start()
{
tr=new Thread(this);
tr.start();
}
public void run() {
while(true)
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
s=("现在时间是:" + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss") .format(new Date()));
}
}
private ImageIcon ico=new ImageIcon("cc.jpg");
public void paintComponent(Graphics g){
g.drawImage(ico.getImage(),0,0,this);
DesktopPane de=new DesktopPane();
de.start();
}
//public void paintComponent(Graphics g)
//{
//g.drawString(s,10,10);
//}
}
展开