Display of time and chaging it every secod or minute


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Display of time and chaging it every secod or minute

  1. #1
    Gangadhar Guest

    Display of time and chaging it every secod or minute


    Hi

    I am learning Java and just finishing core Java. I am trying to build an
    application to display time and update it every second, more or less a stop
    watch . Can any one suggest me a simple solution?

    Thank you

    Gangadhar


  2. #2
    Ashish patel Guest

    Re: Display of time and chaging it every secod or minute


    friend,
    Use thread to display the time.
    Now in thread, get current time.
    That is all u need to do.


    "Gangadhar" <gangadhararao@yahoo.com> wrote:
    >
    >Hi
    >
    >I am learning Java and just finishing core Java. I am trying to build an
    >application to display time and update it every second, more or less a stop
    >watch . Can any one suggest me a simple solution?
    >
    >Thank you
    >
    >Gangadhar
    >



  3. #3
    John Timney (MVP) Guest

    Re: Display of time and chaging it every secod or minute

    Heres an old on screen clock example

    Regards

    John timney (MVP)

    import java.applet.*;
    import java.awt.*;
    import java.util.Date;

    public class mtclock extends Applet {
    public void init() {
    MyThread tm = new MyThread(this);
    tm.start();
    }
    }

    class MyThread extends Thread {
    Date theDate;
    String previousDateText = "";
    String dateText;
    Graphics g;
    Color b, f;

    public MyThread(Applet a)

    g = a.getGraphics();
    b = a.getBackground();
    f = a.getForeground();
    }

    public void paint(Graphics g) {
    g.setColor(b);
    g.drawString(previousDateText,10,30);
    g.setColor(f);
    g.drawString(dateText,10,30);
    previousDateText = dateText;
    }

    public void run() {
    while (true) {
    try {
    theDate = new Date();
    dateText = theDate.toString();
    paint(g);
    this.sleep(1000);
    }
    catch(InterruptedException e) { }
    }
    }
    }





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center