CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2000
    Location
    singapore
    Posts
    6

    Problem to handle long

    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 ?


  2. #2
    Join Date
    Mar 2000
    Location
    Dublin, Ireland
    Posts
    124

    Re: Problem to handle long

    DavidChew,

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

    Do thisate 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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured