aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Add 2D shape to 2D shape and move the first one.  Both should move. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Add 2D shape to 2D shape and move the first one.  Both should move." Watch "Add 2D shape to 2D shape and move the first one.  Both should move." New topic
Author

Add 2D shape to 2D shape and move the first one. Both should move.

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

The title ahead explains exactly what I am trying to do. I want to add a shape to another shape. When I move the first one, I want them both to move (which would happen if I added the 2nd shape to the first).

For example, here is some code. It is not correct and giving me errors. How would I do this?


Hopefully, you can see what I am trying to do. Is there a way to do this?
Thanks,
cc11rocks


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

What do you mean, you want to add one shape to another? You have to be more specific, I can't tell what it is you're trying to do.

Here are some tips I strongly urge you to consider:
- Don't let DBall implement ActionListener and KeyListener. Make separate classes that implement these interfaces (hint: anonymous classes) and add them to your panel instead.
- Don't add a JFrame field to your class. There is nothing your panel does with the frame, so leave the field out. It's not an integral part of your panel. Make it a local variable in your main method instead. Same goes for the content pane.
- Make your fields private. Really. Do this. I mean it.
- Use meaningful identifiers. a, b, c, d are not meaningful. Use x, y, width and height instead.
- Use KeyAdapter instead of KeyListener.

Explain what you're trying to do in line 52.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Below...
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

I just figured it out. You can use points relative to that rectangle.
Eg:

Thank you!
John Price aka cc11rocks

EDIT: Found I didn't need two lines. They are now removed...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Add 2D shape to 2D shape and move the first one. Both should move.