Results 1 to 5 of 5
  1. #1
    rajke88 is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default repaint method called twice?

    Hello people,

    why is repaint method called twice? i have searched online for the answer and i found this:
    paint() in java applet is called twice for no reason - Stack Overflow

    person who suggested the anwer said that there should be JPanel in the interface? should there be a jpanel if im going to make some game that will use g.drawImage method?
    my source code is very similar to the code that i found in that example online. So that are my two questions. Why repaint is called twice, and should applet have jpanel in it or is it ok to draw graphics directly to japplet.

    Thank you in advance in solving my dilema :) i have java experience but i have never used applets so i would need some guide.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,416
    Rep Power
    20

    Default Re: repaint method called twice?

    You have absolutely no control over how many times or how frequently painting methods are called.

    Maybe you would like to go through Painting in AWT and Swing

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    rajke88 is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Re: repaint method called twice?

    DarrylBurke thanks for reply, i will check it out definitely. That will mean that i will have to change logic of my code, and that i have thought in wrong direction, if i can't control how many time paint method is called.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: repaint method called twice?

    Quote Originally Posted by rajke88 View Post
    DarrylBurke thanks for reply, i will check it out definitely. That will mean that i will have to change logic of my code, and that i have thought in wrong direction, if i can't control how many time paint method is called.
    Exactly. Your program should be built with this assumption, and this is one reason that program logic has no business within a component's paint(...) or paintComponent(...) method. You're asking smart questions and making smart inferences.

  5. #5
    rajke88 is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Re: repaint method called twice?

    First thing that came on my mind is to limit system called -> uncontroled paint method triggering, with simple boolean expression. If (painted) {..}. And if i click on button to envoke app triggered painting. For example set painted variable to false and repaint(); Something like that but its rought taught i will have to consider other ways of doing that. Anyways thanks for the kind words Fubarable. When i code something i try to think on all aspects of my program. But thre most important are performance of the software, correct configuration and operability, and security. And as far as i managed to notice, painting methonds within java can have great influence on performance so they should be used carefuly. By the way, this is my little project i started working on yesterday https://www.youtube.com/watch?v=CV7blshTyUI
    Last edited by rajke88; 02-09-2013 at 05:02 PM.

Similar Threads

  1. Why does it seem this method isn't being called?
    By Appel in forum New To Java
    Replies: 7
    Last Post: 05-03-2012, 09:53 AM
  2. panel wont update when repaint is called
    By yemista in forum AWT / Swing
    Replies: 3
    Last Post: 10-25-2011, 06:58 PM
  3. Replies: 5
    Last Post: 10-22-2010, 01:55 PM
  4. while running multiple thread repaint isnt being called....
    By raptor in forum Threads and Synchronization
    Replies: 4
    Last Post: 08-25-2010, 11:47 PM
  5. repaint method
    By manojp476 in forum CLDC and MIDP
    Replies: 10
    Last Post: 08-12-2010, 03:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •