Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing a rectangle but at an angle

 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Graphics2D#rotate(...)
AffineTransform#createTransformedShape(...)
http://download.oracle.com/javase/tutorial/2d/index.html
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Bad. Darryl is correct indeed.
Wonder what I was thinking when I recommended translate.
 
Campbell Ritchie
Sheriff
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you copy your Graphics object before applying transforms. I think you use the Graphics#create() method.
 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks guys for the help. I really appreciate it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic