aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Drawing a rectangle but at an angle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drawing a rectangle but at an angle" Watch "Drawing a rectangle but at an angle" New topic
Author

Drawing a rectangle but at an angle

Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
Hello i'm making a word search game. I want the user of the application to be able to circle the words they find.

At the moment the user can cross out the word. That was no problem as I used drawLine(). Which takes the x1, y1, x2, y2 co-ordinates as arguments. But I can't do the same with drawRectangle or drawRoundRect, because neither take the second x, y co-ordinates but instead take width and height. So I can't think how I could go about drawing a rounded rectangle diagonally down, or diagonally up.

Is there another method somewhere that can do this? Am I missing something simple?

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9995
    
    7

I want the user of the application to be able to circle the words they find....how I could go about drawing a rounded rectangle diagonally down, or diagonally up.


Check out Graphics#translate
However, Graphics#drawOval will be easier.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
Ok thanks I will check it out when i get home. So are you saying there is a way for me to do what i want just by using drawOval?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Graphics2D#rotate(...)
AffineTransform#createTransformedShape(...)
http://download.oracle.com/javase/tutorial/2d/index.html


luck, db
There are no new questions, but there may be new answers.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9995
    
    7

My Bad. Darryl is correct indeed.
Wonder what I was thinking when I recommended translate.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
I suggest you copy your Graphics object before applying transforms. I think you use the Graphics#create() method.
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
Ok, thanks guys for the help. I really appreciate it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Drawing a rectangle but at an angle
 
Similar Threads
Comparing co-ordinates
label
tooltip
To get the coordinates of mouse pointer...
Problem in finding the bounds of rectangle.....