Results 1 to 11 of 11

Thread: repaint method

  1. #1
    manojp476 is offline Member
    Join Date
    Apr 2010
    Posts
    4
    Rep Power
    0

    Default repaint method

    when I call repaint() method it does not execute paint(graphics g) method.
    when I call paint(graphics) method directly then it gives exception.

    now is their any way to execute paint() without calling repaint() method ?

    Is their any algorithm which can replace repaint() method?

  2. #2
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Smile Repaint() Error

    Hey I m also facing the same problem ....You got some Solution to this.. if yes please post it immediately its urgent...

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Why do you want to call paint() directly?
    YOu might want to if you have created your own Graphics object and want to paint it and then create an image from that to save to disk .
    But if you want to update the GUI display, you call repaint() to tell the JVM to call your paint method with the correct graphics object and on the correct thread.

  4. #4
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    @Norm

    thanks for the reply. Sir m using two threads. one is system thread that is handling key events and another thread is its child thread created explicitly that is handling the graphics painting process. the child thread is used to call repaint method repeatedly after a particular period of time. for that i had used sleep(); declared inside a loop in the Run() method the entry point a thread.
    Side by side the main thread handles the key events and paint() method draw the graphics accordingly.

    now the issue is that i want to create a flashing effect on a particular line .. for that i had used a variable LINEDRAW....in paint() if LINEDRAW is 1 then it draws the line else not...
    now in key event

    following algo is defined:-

    LINEDRAW=1;
    Thread.sleep(100); // sleep the main thread that is handling the keyevents
    LINEDRAW=0;
    Thread.sleep(100); // sleep the main thread that is handling the keyevents
    LINEDRAW=1;
    Thread.sleep(100); // sleep the main thread that is handling the keyevents

    the painting process should be handled parallely by the child thread created explicitly.
    Now the flashing effects is seen only more delay in the painting process is seen..
    ...
    I dont know y it is happening? Need serious help ... might be there may be the issue with the Threads... also tell me how to obtain reference to main Thread also how to know how many THREADS are running at a particular number of time in the program...

    THANKS & REGARDS
    Last edited by nitin_daviet88; 08-04-2010 at 07:27 AM.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    YOU need to tell the GUI system that that the LINEDRAW variable has changed and that you want the GUI system to call the paint() method to do the drawing that the LINEDRAW variable requests.
    You do that by calling the repaint() method. Some time later the GUI system will call the paint method to do the new drawing.

  6. #6
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    yes sir i had done the same thing... actually repaint() statement is running in a loop it is called after every 1 second this is handled by the child i created.

    sir once i stopped this loop and start calling paint() whenever required that too doesnt work.... i dont know y ?


    LINEDRAW=1;
    repaint();
    Thread.sleep(100); // sleep the main thread that is handling the keyevents
    LINEDRAW=0;
    repaint();
    Thread.sleep(100); // sleep the main thread that is handling the keyevents
    LINEDRAW=1;
    repaint();
    Thread.sleep(100); // sleep the main thread that is handling the keyevents


    this too doesnt work . then i used S.O.P. to check the Flow of the block....


    LINEDRAW=1;
    System.out.println("About to call Paint method");
    repaint();
    System.out.println("After calling paint method");
    Thread.sleep(100); // sleep the main thread that is handling the keyevents
    LINEDRAW=0;
    System.out.println("About to call Paint method");
    repaint();
    System.out.println("After calling paint method");
    Thread.sleep(100); // sleep the main thread that is handling the keyevents
    LINEDRAW=1;
    System.out.println("About to call Paint method");
    repaint();
    System.out.println("After calling paint method");
    Thread.sleep(100); // sleep the main thread that is handling the keyevents



    Inside the paint() there's a statement :-

    System.out.println("Paint is called");


    Now the following output was obtained:-

    About to call Paint method
    After calling paint method

    About to call Paint method
    After calling paint method

    About to call Paint method
    After calling paint method


    No PAINT IS CALLED was found..
    now it only leaves the inference that repaint() statement was not Implemented by the system.... Hope you got the problem.... Sir I need to Implement the flashing effect of line in the program.... that too Within 2 days.....

    This JAVA programming is killing me.........

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    No PAINT IS CALLED was found.
    Try putting:
    @Override
    before the paint method definition to make sure you are actually overriding the method. A spelling error or wrong args would create a new method vs overriding the paint method.

  8. #8
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    Sir , M using NetBeans IDE for the development. It indicates that paint() is overridden by the my paint() defination...
    it indicates multiple Annotations if i place @override statement before that......


    Thanks & Regards

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    it indicates multiple Annotations
    Sorry, I don't know anything about your IDE and its warning/error messages.

    How many different classes do you have that you have overridden the paint() method in?
    Are any of them called when you do a repaint()?

  10. #10
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    Sir

    I need some help on Threads...
    There are two threads A & B.
    One Method--Gamepaint();


    Both threads call the Gamepaint();;
    the Array variables used in Gamepaint() are Initialized and set by Thread B at regular interval of time by calling another method SetFlash()... and simultaneously the Thread A accesses those variables by calling Gamepaint();


    when this happens in a loop it generates an array_index_out_of_bound EXCEPTION

    when run for one time it works well...
    i want that Thread A should not access variables in gamepaint(); before it had been set by Thread B By calling setFlash();;;;

    Hope you got the problem..

    Thanks & Regards

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    i want that Thread A should not access variables in gamepaint();
    I'm not sure what that means.
    If the variables are local to the gamepaint() method, how can code in another method access them?
    A thread doesn't have variables.

    If you want different callers of a method to have/use their own data, put the data in an object and have each caller pass that object to the method.

Similar Threads

  1. repaint every
    By 3xpr1ment in forum AWT / Swing
    Replies: 10
    Last Post: 03-23-2010, 05:39 PM
  2. Trying to do a simple repaint
    By IYIaster in forum New To Java
    Replies: 9
    Last Post: 10-14-2009, 10:30 PM
  3. repaint problem
    By amith in forum Java 2D
    Replies: 2
    Last Post: 07-01-2008, 12:10 AM
  4. Problem in repaint
    By Preethi in forum AWT / Swing
    Replies: 16
    Last Post: 03-18-2008, 08:10 PM
  5. Repaint problem
    By swimberl in forum Java 2D
    Replies: 0
    Last Post: 01-06-2008, 03:28 AM

Posting Permissions

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