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

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);
}
}