"Date now = new Date();"中的“now”是什么语法含义。
武者 2011-08-20 09:53:46 源码如下:
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class ThreeClocks extends Panel implements Runnable{
private int timee;
private Thread thd;
public ThreeClocks(int t){
timee=t;
thd=new Thread(this);
thd.start();
}
public void run(){
while(thd!=null){
repaint();
try{
thd.sleep(timee);
}catch(InterruptedException e){}
}
}
public void paint(Graphics g){
Date now=new Date(); //"Date now = new Date();"中的“now”是什么语法含义。
g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,10);
}
public static void main(String args[]){
ThreeClocks Clock1,Clock2,Clock3;
Clock1=new ThreeClocks(1000);
Clock2=new ThreeClocks(5000);
Clock3=new ThreeClocks(10000);
Frame f=new Frame("Three Clocks running together");
f.setSize(200,100);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(1);}});
f.setLayout(new GridLayout(1,3));
f.add(Clock1);
f.add(Clock2);
f.add(Clock3);
}
}