File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes multiple painting components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "multiple painting components" Watch "multiple painting components" New topic
Author

multiple painting components

Rick Gentry
Ranch Hand

Joined: Dec 14, 2002
Posts: 63
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

Joined: Dec 06, 2001
Posts: 3061
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?


Java API Documentation
The Java Tutorial
Rick Gentry
Ranch Hand

Joined: Dec 14, 2002
Posts: 63
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple painting components