Results 1 to 9 of 9
Thread: update() gets never called
- 10-16-2009, 02:44 PM #1
Member
- Join Date
- Sep 2009
- Location
- Gouda, the Netherlands
- Posts
- 24
- Rep Power
- 0
update() gets never called
Hi,
From what I understand at java.sun.com/products/jfc/tsc/articles/painting/ , repaint() lets awt call update(). But what you can see with the following code, what gets called is paint()! Am I doing something wrong? What?
Thanks.
Java Code:import java.awt.*; import javax.swing.*; public class pu extends JFrame { public void paint(Graphics g) { System.out.println("paint"); } public void update(Graphics g) { System.out.println("update"); } public static void main(String[] arg) { try { /* retrieve max window size */ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); GraphicsConfiguration [] gc = gs[0].getConfigurations(); Rectangle r = gc[0].getBounds(); /* create frame to draw in */ pu frame = new pu(); frame.setSize(r.width, r.height); System.out.println("set visible"); frame.setVisible(true); for(;;) { System.out.println("Invoke repaint"); frame.repaint(); System.out.println("Sleep"); Thread.sleep(1000); } } catch(Exception e) { System.out.println("exception " + e); } } }
- 10-16-2009, 02:50 PM #2
I think if you want to draw a string on a frame by using paint() method, you must use the drawString() method of class Graphics.
Write a program to achieve anything you want in your life!
- 10-16-2009, 02:59 PM #3
Member
- Join Date
- Sep 2009
- Location
- Gouda, the Netherlands
- Posts
- 24
- Rep Power
- 0
- 10-16-2009, 03:05 PM #4
the method repaint() will call paint() method because you are using a lightweight (Swing) component. Try a heavyweight component (AWT) instead. I think it works!
Write a program to achieve anything you want in your life!
- 10-16-2009, 03:19 PM #5
Member
- Join Date
- Sep 2009
- Location
- Gouda, the Netherlands
- Posts
- 24
- Rep Power
- 0
[SOLVED] JFrame -> Frame
- 10-16-2009, 03:25 PM #6
You are welcome!
Anyway, do you have the JDK Documentation with you? If not, download one here. It is the best reference for all programmers.Write a program to achieve anything you want in your life!
-
But I don't understand why it is important that update gets called here. All update does in swing is call paint(), something which repaint already does (indirectly). I will posit that regardless you are far better off using Swing and its lightweight components, that there is a better way of solving whatever underlying problem you are having that makes you feel impelled to override update().
- 10-19-2009, 04:20 PM #8
Member
- Join Date
- Sep 2009
- Location
- Gouda, the Netherlands
- Posts
- 24
- Rep Power
- 0
- 10-19-2009, 04:45 PM #9
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
It appears you don't understand how painting works. Remember, your original question was about JFrame, which indicates you are attempting to create a Swing application.
In Swing custom painting is done by overriding the paintComponent() method of a component like JPanel.
When using AWT custom painting was done by overriding paint() and update(). I find people generally use this approach because they found some 10 year old code lying around.
People generally use Swing over AWT because it is far more flexible, more current and advanced than AWT.
Similar Threads
-
doPost() is not called in servlet logic
By bubulina in forum Java ServletReplies: 6Last Post: 10-28-2009, 10:19 AM -
ok so i have to write a program called FourRectanglePrinter
By jcoon3 in forum New To JavaReplies: 0Last Post: 09-22-2009, 07:15 PM -
My constructor not called
By rdtindsm in forum New To JavaReplies: 2Last Post: 09-20-2009, 01:38 AM -
Return objects called
By MV1 in forum New To JavaReplies: 7Last Post: 03-11-2009, 07:16 AM -
javascipt function is nt getting called
By pankaj_salwan in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-20-2008, 08:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks