The Artima Developer Community
Sponsored Link

Java Answers Forum
PLS HELP -Urgent

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

PLS HELP -Urgent Posted: Mar 4, 2006 3:12 PM
Reply to this message Reply
Advertisement
Could anybody pls pls tell me what is the problem with my following code which is a simple clock(no compile error but doesnt show the time)-

import java.util.*;
import java.text.DateFormat;
import java.awt.*;
import java.awt.geom.*;
public class Clock extends Frame implements Runnable
{

public void run() {
Thread myThread = Thread.currentThread();
while (myThread !=null) {
repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException e){

}
}
}
public void paint(Graphics g) {
// get the time and convert it to a date
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
// format it and display it
DateFormat dateFormatter = DateFormat.getTimeInstance();
g.drawString(dateFormatter.format(date), 5, 10);
}
//public void update(Graphics g)
//{ paint(g) ; }

Clock(){

setBounds(300,200,200,200);
setVisible(true);

}
public static void main(String str[])
{
Clock myclock=new Clock();
Thread myThread=new Thread(myclock);
myThread.start();
}

}

[how to use repaint method in java console programe(not in applet).when to use repaint and when to use update method and why. could u pls write me a prorgame which has a button that draw something upon being pressed on the frame or just give hints how to do it]

Topic: help plz... Previous Topic   Next Topic Topic: RMI question from Java Examples in a Nutshell

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use