The Artima Developer Community
Sponsored Link

Java Answers Forum
Java Repaint method

5 replies on 1 page. Most recent reply: Oct 4, 2007 9:51 AM by Mridul J

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 5 replies on 1 page
Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

Java Repaint method Posted: Feb 27, 2006 5:27 PM
Reply to this message Reply
Advertisement
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();
}

}


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Java Repaint method Posted: Feb 28, 2006 1:50 AM
Reply to this message Reply
reformat your code using the java tags as shown on the right side of the input field, then someone might actually read it.

Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

Re: Java Repaint method Posted: Mar 4, 2006 6:07 PM
Reply to this message Reply
What do u mean by- "reformat your code using the java tags as shown on the right side of the input field, then someone might actually read it".where is d"input field". n wat is "tag"

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Java Repaint method Posted: Mar 6, 2006 4:50 AM
Reply to this message Reply
1. Click on "reply"

2. Move your eyes to the right.

3. READ!

Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

Re: Java Repaint method Posted: Apr 22, 2006 3:04 PM
Reply to this message Reply
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

Mridul J

Posts: 1
Nickname: javacoder
Registered: Oct, 2007

Re: Java Repaint method Posted: Oct 4, 2007 9:51 AM
Reply to this message Reply
Hi,
I believe you are not able to display the clock because the frame component doesn't have a body implementation.
it is possible to display on the title bar of the frame using the setTitle method.
I would suggest you extend the Clock class from Applet.
Since I am a novice, I am not sure of this. If you do manage to implement please do let me know. :). Bye.

Flat View: This topic has 5 replies on 1 page
Topic: Java Repaint method Previous Topic   Next Topic Topic: inject entity manager in JSF managed bean


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us