title: Mouse listener not giving the right points
body: <p>I am making a program that draws different shapes based on user input. The shapes are drawn when the cursor is pressed and dragged. But for some reason whenever the cursor is pressed, the shapes are starting about 25 pixels below the cursor. Anyone know why and how to fix it?</p>
  
  <p>My code</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  import java.awt.geom.*;
  
  
  public class DrawShapes extends JFrame
  {
      private JLabel display;
      private Point point1, point2;
      private ShapeDrawer drawer;
  
  public DrawShapes()
  {
      Container contain = getContentPane();
  
      point1 = null;
      point2 = null;
  
      //Setup JLabel and add it to container
      display = new JLabel("Line");
      contain.add(display, BorderLayout.SOUTH);
  
      //Setup JPanel and add it to top of container
      drawer = new ShapeDrawer();
      drawer.setPreferredSize(new Dimension(500,500));
      contain.add(drawer, BorderLayout.NORTH);
  
      //Setup listeners
      ShapeListener  listener = new ShapeListener();
      addKeyListener(listener);
      addMouseListener(listener);
      addMouseMotionListener(listener);
  
      setTitle("Press l for line, o for oval, r for rectangle");
      pack();
      setVisible(true);
  }
  
  //Class for drawing shapes
  private class ShapeDrawer extends JPanel
  {
      public void paintComponent(Graphics paint)
      {
          super.paintComponent(paint);
  
          Graphics2D g2 = (Graphics2D) paint;
          setBackground(Color.white);
          g2.setColor(Color.black);
  
          //Draw different shapes based on user input
          if(point1 != null &amp;&amp; point2 != null)
          {
              if(display.getText().equals("Circle"))
              {
                  g2.fillOval(point1.x - 6, point1.y - 6,
                          6* 2, 6 * 2);
              }
              else if(display.getText().equals("Oval"))
              {
                  g2.drawOval(point1.x,point1.y,point2.x,point2.y);
              }
              else if(display.getText().equals("Line"))
              {
                  g2.drawLine(point1.x, point1.y, point2.x, point2.y);
              }
              else if(display.getText().equals("Rectangle"))
              {
                  g2.drawRect(point1.x, point1.y, point2.x, point2.y);
              }
          }
      }
  }
  
  private class ShapeListener implements MouseListener, MouseMotionListener ,KeyListener
  {
      //Change the label if something else is pressed
      public void keyPressed(KeyEvent event)
      {
          if(event.getKeyText(event.getKeyCode()).equals("C"))
              display.setText("Circle");
          else if(event.getKeyText(event.getKeyCode()).equals("O"))
              display.setText("Oval");
          else if(event.getKeyText(event.getKeyCode()).equals("R"))
              display.setText("Rectangle");
          else if(event.getKeyText(event.getKeyCode()).equals("L"))
              display.setText("Line");
      }       
  
      public void keyReleased(KeyEvent event){};
      public void keyTyped(KeyEvent event){};
  
      //Get first point where mouse is pressed
      public void mousePressed(MouseEvent event)
      {
          point1 = event.getPoint();
  
      }
  
      //Get the point while mouse is being pressed
      public void mouseDragged(MouseEvent event) 
      {
          point2 = event.getPoint();
          drawer.repaint();
  
      }
  
      public void mouseReleased(MouseEvent event) {}
      public void mouseEntered(MouseEvent event) {}
      public void mouseExited(MouseEvent event) {}
      public void mouseClicked(MouseEvent event) {}
      public void mouseMoved(MouseEvent event) {}
  
  
  
  }
  }
  </code></pre>
  
  <p>and the main method</p>
  
  <pre><code>import javax.swing.JFrame;
  class ShapesViewer
  {
  public static void main(String[] args)
  {
      DrawShapes shapes = new DrawShapes();
  
      shapes.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  }
  </code></pre>