Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple painting components

 
Rick Gentry
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two JComponents that both call paint, and they paint over each other so only one shows and the other disappears entirely. I can guess a few ways to fix that, but they are long and drawn out. Is there an easier way? Code is below if you want to see it. Problem is in the ball class.

[ May 13, 2003: Message edited by: Rick Gentry ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Umm...is it a Pong game? :roll:
I assume that the Ball component is writing over the Paddle, or vice versa. It seems if you add some collision detection logic, this won't be a problem. In other words, you need to add the functions that detect whether the ball hits either of the paddles.
This is kind of interesting because I've thought of implementing something similar. I've already got the bouncing ball working, but I haven't done the paddles yet. Did you get the threaded Ball idea from the book Core Java 2 Vol II?
 
Rick Gentry
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Layne Lund:
Umm...is it a Pong game? :roll:
I assume that the Ball component is writing over the Paddle, or vice versa. It seems if you add some collision detection logic, this won't be a problem. In other words, you need to add the functions that detect whether the ball hits either of the paddles.
This is kind of interesting because I've thought of implementing something similar. I've already got the bouncing ball working, but I haven't done the paddles yet. Did you get the threaded Ball idea from the book Core Java 2 Vol II?

If you read the code, you'll see that the Paddle class is empty and main() creates no paddles so the problem isn't there. main() does create two Balls. The second ball overwrites the first ball so that only the second ball is visible. I guess what I'm looking for is an easy way to get everything to appear individually without messing with rectanges or clearing the screen. (just move the picture associated with the JComponent)
I'm borrowing my ideas from Learning Java from O'Reilly if you're interested.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic