Recall that the coordinate axes in a JPanel starts at the upper left
corner and that the y-axis is pointed down, rather than up.
This arrangment can be unnatural for specifying the coordinates of many
objects, since we normally think of the origin as being at the lower
left corner of a window and the y-axis as moving up.
Assuming that you have a Graphics2D object
g2, show the Java transforms you would call in order to move
the origin to the lower left corner and make the y-axis point up. You
do not have to place your code in a java file. I just want to see the
code fragment you would write
to transform g2 to change the coordinate axes using a
combination of the Graphic2D class's translate and
scale methods. As an example,
if you draw a rectangle at coordinates (20, 20), I would expect the
rectangle to be drawn at an offset of (20, 20) from the bottom left
corner of the JPanel, rather than the upper left corner, as shown below:
If you re-sized the JPanel, the rectangle would stay attached to the
lower left hand corner of the JPanel.
To provide context, you would insert your code into the following
code fragment:
public void paintComponent(Graphics g) {
super.paintComponent(g);
Rectangle r = new Rectangle(20, 20, 200, 100);
Graphics2D g2 = (Graphics2D) g;
AffineTransform saveTransform = g2.getTransform();
// YOUR CODE FOR MODIFYING g2's TRANSFORM MATRIX GOES HERE
g2.draw(r); // draws rectangle in the lower left corner of the JPanel
g2.setTransform(saveTransform);
}