package com.qmxy;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class stopWach extends Canvas
{
long stattime=0;
long endtime=0;
public void paint(Graphics g){
SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
Date date=null;
try {
date = sdf.parse("00:00:00");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
date.setTime(date.getTime()+(stattime-endtime));
String str=sdf.format(date);
g.fill3DRect(0, 0, 78, 28, false);
g.drawString(str,10,20);
g.setColor(Color.WHITE);
}
}
public class Test extends Frame
{
public Test(){
this.add(new stopWach());
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
e.getWindow().dispose();
System.exit(0);
}
});
}
public static void main(String[] args)
{
Test stopwawch=new Test();
stopwawch.setVisible(true);
stopwawch.setSize(200,300);
}
} |