Question: When I draw lines in my program the position is perfect, but when I use those same coordinates for a square or oval they are way off the mark. My code is:

```
g2d.drawRect(one1, one2, two1, two2);
g2d.drawOval(one1, one2, two1, two2);

```

And the points are gather by:

```
one1 = (int)e.getX();
one2 = (int)e.getY();

```

This is a follow on to a [question I previously asked](https://stackoverflow.com/questions/8479432/lines-arent-drawing-exactly-where-i-clicked).

Answer: 
Alright, I got what your problem is. If you see the below image, the way that the parameters taken by oval and sqaure are different from the line.

To draw a line --> You will have to specify the starting point and the ending point. Just passing them directly to the Graphics object would do the job for you. However for a Square or Oval, it is different. You first click will grab a point and then you should do some manipulation on what should be the output when you do the second click. The second click should not be considered as a co-ordinate into the drawOval() or drawRect() methods directly.

Because the Parameter for these methods are 

```
x, y, width, height

```

Whereas you are getting

```
x1, y1  and x2, y2

```

![enter image description here](https://i.stack.imgur.com/lyEdU.png)

```
package sof;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class DrawTest {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Draw Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MyComponent());
        frame.setSize(260, 280);
        frame.setVisible(true);
    }
}

class MyComponent extends JComponent {
    public void paint(Graphics g) {
        int height = 120;
        int width = 120;
        g.setColor(Color.black);
        g.drawOval(60, 60, width, height);
        g.drawRect(60, 60, width, height);
        g.drawLine(0,0,50,50);
    }
}

```
I think I understand what your issue is. You are having the user click in two different spots on the canvas and then you want to draw a rectangle/oval using those points. So if the user clicks at 10,10 and then clicks at 20,20, then you want a rectangle whose top left corner is at 10,10 and whose bottom right corner is at 20,20.

If this is in fact what you are asking, then here is my proposed solution:

```
Event e1 = (the first click)
Event e2 = (the second click)

// Figure out where the user clicked
int x1 = (int)e1.getX();
int y1 = (int)e1.getY();

int x2 = (int)e2.getX();
int y2 = (int)e2.getY();

int xCoord;
int yCoord;

// Figure out the coordinates
if(x1 < x2)
    xCoord = x1;
else
    xCoord = x2;

if(y1 < y2)
    yCoord = y1;
else
    yCoord = y2;

// Figure out the size of the object
int width = Math.abs(x1 - x2);
int height = Math.abs(y1 - y2);

// Finally draw your objects
g2d.drawRect(xCoord, yCoord, width, height);
g2d.drawOval(xCoord, yCoord, width, height);

```

That should work for you based on my understanding of your question.