How can I draw a rectangle towards the top of the application in java ? Normally the drawRect method draws towards the bottom I tried to use a negative number but this would not work
Graphics g = p.getGraphics();
g.fillRect(50, 200,50,100);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In rectangles, the X and Y coordinates represent the top left corner. The length and width then draw away from the defining point. Your example draws a rectangle with the top left corner at 50,200 and with a width of 50 and a hight of 100, both away from those points in a positive direction. If you wanted a rectangle with 50,200 representing the lower left corner, simply subtract the height from that y coordinate (200), and use that as the starting y:
To address your examples, try something like this (I’ll just use rectangle objects rather than
actually filling the graphics):
After filling rectangles with these dimensions on the graphics object, you’ll have three
rectangles with a width of 50 each, spaced 50 apart, with the bottom all on the y=200 line.