title: why does simply switching from Frame to JFrame cause such a big difference?
body: <p>This code displays x and y points based on where you click. I want to add a JPanel so that the frame does not start measuring from the title bar which is unreachable to the user.</p>
  <p>Every time I switch from Frame to JFrame I get this:</p>
  <p><a href="https://i.stack.imgur.com/Ckq9a.png" rel="nofollow noreferrer">example</a></p>
  <p>The previous click does not disappear... What is the easiest way to fix this or am i able to add a JPanel on a Frame?</p>
  <p>Below is my code:</p>
  <pre><code>************************************************************/
  
  import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  import java.awt.Color;
  
  public class Proj07Runner {
    Proj07Runner(){
      System.out.println(
      &quot;Terminal text&quot;);
      GUI gui = new GUI(); //instantiate a GUI
    }//end main
  }
  
  **Here is where switching from Frame to JFrame causes the change**
  class MyFrame extends JFrame{
    int clickX;
    int clickY;
  
    public void paint(Graphics g){
      g.setColor(Color.BLACK);
      g.drawString(
               &quot;&quot; + clickX + &quot;, &quot; + clickY, clickX, clickY);
    }//end paint()
  }
  
  
  class GUI {
    public GUI(){//constructor
      //Create a new JFrame object, set size, title, etc.
      MyFrame displayWindow = new MyFrame();
      JPanel myPanel = new JPanel();
      displayWindow.setSize(300,100);
      displayWindow.setTitle(&quot;Title&quot;);
      myPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
  
  
      displayWindow.setVisible(true);
      //Instantiate and register an anonymous Listener;
      // object which will terminate the program when the;
      // user closes the JFrame.
      displayWindow.addWindowListener(new WProc1());
  
      myPanel.addMouseListener(
                               new MouseProc(displayWindow));
      displayWindow.addMouseListener(
                               new MouseProc(displayWindow));
                               
            
    }
  }
  
  //This listener class monitors for mouse presses and;
  // displays the coordinates of the mouse pointer when the
  // mouse is pressed on the source object. Note that this
  // class extends is an adapter class.
  class MouseProc extends MouseAdapter{
    MyFrame refToWin; //save a reference to the source here
    MouseProc(MyFrame inWin){//constructor
      refToWin = inWin;//save ref to window
    }//end constructor
  
    //Override the mousePressed method to determine and;
    // display the coordinates when the mouse is pressed.
    public void mousePressed(MouseEvent e){
      //Get X and Y coordinates of mouse pointer and store
      // in an instance variable of the JFrame object
      refToWin.clickX = e.getX();
      refToWin.clickY = e.getY();
      //refToWin.clearRect(0,0,300,100);
  
      // Force the JFrame object to be repainted in order to
      // display the coordinate information.
      refToWin.repaint();
    }//end mousePressed()
  }
  
  //The following listener is used to terminate the program
  // when the user closes the frame.  Note that this class
  // extends an adapter class.
  class WProc1 extends WindowAdapter{
    public void windowClosing(WindowEvent e){
      System.exit(0);
    }
  }
  </code></pre>