Draw a rhombus
I need to draw a rhombus into a JComponent. I ain't so familiar with the Graphics & Graphics2D classes, so I'd like to ask you if somebody could help me. I thought of drawing each of the four lines that will be the rhombus' faces, but I don't know how to have them really painted into a component, or similar.
Thank you in advance for the answers
Check out this tutorial: Painting in AWT and Swing
But basically, you just want to extend a JPanel (or JComponent), override paintComponent, and do your custom painting in that method.
Check out the API for Graphics and Graphics2D for useful drawing methods.
I second Kevin's recommendations since you need to understand the concepts in these tutorials before anyone can help you, and in fact I recommend the Swing tutorial and API in general as the first resource you should check out for questions such as these. Then if you get stuck and your code doesn't work, please come on back, show us your code and we'll be better able to help you.
Best of luck!
You should do some tutorials on how to draw first, that is how I learnt.
An easy way would be to make a rectangle, and then rotate it, and then scale it.
Look up the graphics API for scale, rotate, draw, JFrames and rectangles.
Sorry, but that's about the most difficult way I could think of (and you would start with a square, not a rectangle).
Originally Posted by Rectal Exambot
The Polygon class might be worth a try. But as already mentioned, only after going through some tutorials on custom painting.
Rotated and scaled rectangles are still rectangles... (or are we thinking of stretching them?) STarting with a rectangle, what you would do is join its midpoints.
Using Graphics2D it isn't that difficult:
Originally Posted by Darryl.Burke
1) rotate around 45 degrees
2) apply a nice scaling
3) draw a rectangle with equal sides (a square)