Results 1 to 3 of 3
  1. #1
    sahhhm is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default Working around paintcomponent

    Hello,

    I currently have a class which acts as a display panel for my entire program and which contains a paintcomponent. There is a Key Listener which invokes a repaint method. However, I was wondering if there was a way to have another method which draws something on the paintcomponent without being invoked by the repaint method in the Key Listener repaint.

    I hope this makes sense,
    Regards,
    Sam

  2. #2
    kinabaloo is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default hi

    You will have to give more details. Why not simply call paintComponent.repaint() from the other method? I guess you have something else in mind - but what ?

  3. #3
    sahhhm is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default More Detail

    Let me try and clarify from my original post (Sorry for the ambiguity):

    I am relatively inexperienced in Java, having only taken an introductory semester at my University. I am currently working on my own version of Number Munchers. The game essentially revolves around a green muncher trying to eat valid numbers (based on the level) while "bad munchers" roam about freely attempting to land in the same square as the green muncher.

    My version of the game successfully implements the ability of the green muncher to move, via the KeyListener, validates answers when the space button, etc. The KeyListener sets the green muncher's new position and then call the repaint() method, allowing for the newly moved muncher to be displayed in its new position.

    The problem I am running into is utilizing the "bad munchers" which are their own object. The point of the bad munchers is that they move freely, obviously without any input from the user. I have an object representing these bad munchers and store htem in an arrayList of munchers. The method I invoke to determine when a bad muncher is displayed is heavily time-based. The problem occurs when I place this method in the paintcomponent, because everytime the KeyListener is invoked and the repaint method is called, the "bad muncher" method is recalled over and over again.

    Is there a way to avoid this problem? (I think that perhaps some boolean logic may be used, but am wondering if there is a better approach.)

    Thanks again,
    Sam

Similar Threads

  1. Replies: 7
    Last Post: 04-14-2009, 07:12 PM
  2. Problem going outside paintComponent
    By Thez in forum Java 2D
    Replies: 9
    Last Post: 12-08-2007, 04:59 PM
  3. Drawing outside paintComponent()
    By DarkSide1 in forum Java 2D
    Replies: 2
    Last Post: 11-08-2007, 10:36 PM
  4. paint() and paintComponent()
    By goldhouse in forum Java 2D
    Replies: 1
    Last Post: 07-17-2007, 03:43 AM
  5. Working With ANT
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 08:16 PM

Posting Permissions

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