Click to See Complete Forum and Search --> : Problem to handle long


davidchew
May 3rd, 2000, 06:40 AM
I had some problem to display a long number
with a g.drawstring command. Can somebody help ?

for example in the following codes :
Date earlierDate = new Date(71,7,1,7,10);
long earliersecs = earlierDate.getTime();
public void paint(Graphics g) {
g.drawString(earliersecs,10,50);
}

The compiler replies with an error because
earliersecs is a long. How do I solve this problem
to display a long in an applet ?

dogbear
May 3rd, 2000, 08:19 AM
DavidChew,

You simply need to convert the long to a String object.
The Graphics.drawString() method takes a String only.

Do this:Date earlierDate = new Date(71,7,1,7,10);
long earliersecs = earlierDate.getTime();

public void paint(Graphics g) {
String earlierSecsString = Long.toString(earliersecs);
g.drawString(earlierSecsString ,10,50);
}

This should work for you.
Look at the API for the java.util.* classes for different type conversions. They are really handy.

Regards,
dogBear