This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Draw Rectangle Only

 
Charles Sexton
Ranch Hand
Posts: 272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason I can't wrap my head around this. I can draw a rectangle or square perfectly by mouse drag but I don't want a rectangle to be drawn as a square. This is a school assignment and I have to do the same for an oval and circle. I was hoping maybe someone can help me with the rectangle and square. I will try to figure out the circle and oval after help.


This is the rectangle draw method.

 
Stephan van Hulst
Bartender
Pie
Posts: 6503
83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use Graphics.fillRect() and Graphics.drawRect(). Have you taken a look at other methods of the Graphics class?
 
Charles Sexton
Ranch Hand
Posts: 272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:You use Graphics.fillRect() and Graphics.drawRect(). Have you taken a look at other methods of the Graphics class?


Yes and I just looked again at the Graphics API and I don't see anything that would prevent me from drawing a square. I have been playing with the starting point and the ending point as I was thinking that the issue could be solved with the x and y coordinates of both.
 
Stephan van Hulst
Bartender
Pie
Posts: 6503
83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I misinterpreted what you meant. What's the problem exactly? If your width and height are different, you should be drawing a rectangle, yeah?
 
Rob Camick
Ranch Hand
Posts: 2673
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want a rectangle to be drawn as a square.


I don't understand the requirement. A square just happens to be a rectangle were the width and height are the same values.

What is the point of this requirement. If the user selects Rectangle and happens to make the width and height equal what would you do? Would you randomly change one of the values by a pixel so it is not a square?
 
Charles Sexton
Ranch Hand
Posts: 272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
I don't want a rectangle to be drawn as a square.


I don't understand the requirement. A square just happens to be a rectangle were the width and height are the same values.

What is the point of this requirement. If the user selects Rectangle and happens to make the width and height equal what would you do? Would you randomly change one of the values by a pixel so it is not a square?


Yes Rob has it but I don't know how to figure out if the square is equal on all sides.
 
Rob Camick
Ranch Hand
Posts: 2673
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to figure out if the square is equal on all sides.


I already answered that.
 
Charles Sexton
Ranch Hand
Posts: 272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
I don't know how to figure out if the square is equal on all sides.


I already answered that.


Sorry about that Rob, lack of sleep. Two final exams and then this project. Im also having to study c sharp for a software QA testing position at tekSystems.
 
Charles Sexton
Ranch Hand
Posts: 272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API when I was looking earlier I did catch something. The fillRectangle() method fills the rectangle and drawRectangle() outlines the rectangle. Couldn't just filling the rectangle and not calling the drawRectangle() change the pixel size by one or so? Also my code shouldn't set color twice but before the if statement.
 
Piet Souris
Rancher
Posts: 1530
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a bit confusing what java considers to be the witdh and height.
So do a little experiment, something like:

and notice the difference, if any.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic