Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-14-2008, 05:38 AM
Member
 
Join Date: May 2008
Posts: 3
sahhhm is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-16-2008, 12:26 AM
Member
 
Join Date: May 2008
Posts: 6
kinabaloo is on a distinguished road
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 ?
__________________
Kinabaloo

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-16-2008, 04:43 AM
Member
 
Join Date: May 2008
Posts: 3
sahhhm is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to draw a fill rectangle using mouse and paintComponent? java_fun2007 New To Java 5 10-23-2008 11:52 AM
Problem going outside paintComponent Thez Java 2D 9 12-08-2007 06:59 PM
Drawing outside paintComponent() DarkSide1 Java 2D 2 11-09-2007 12:36 AM
paint() and paintComponent() goldhouse Java 2D 1 07-17-2007 05:43 AM
Working With ANT JavaForums Eclipse 0 04-26-2007 10:16 PM


All times are GMT +3. The time now is 03:23 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org