|
Re: Java Repaint method
|
Posted: Apr 22, 2006 12:04 PM
|
|
could anybody tell me(novice) 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. 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(); }
}
Now is it OK Mr. Matthias Neumair
|
|