title: Constantly updating JFrame text
body: <p>I am new to java development, and decided to create a simple java project that outputs the X and Y coordinates of where the mouse is inside of a jframe. I am unsure how I would use a listener.</p>
  
  <pre><code>package main;
  
  import java.awt.BorderLayout;
  import java.awt.MouseInfo;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.SwingConstants;
  
  public class Main {
  public static void main(String[] args) {
  jFrame();
  }
  
  public static void jFrame() {
      JFrame myFrame = new JFrame("Screen Location");
      myFrame.setVisible(true);
      myFrame.setBounds(0, 0, 300, 100);
      JLabel myText = new JLabel(""+ getTotal(),
          SwingConstants.CENTER);
      myFrame.getContentPane().add(myText, BorderLayout.CENTER);
  }
  
  private static String getTotal() {
      for (int i = 0; i &lt; 1;) {
      int publicScreenValueX = MouseInfo.getPointerInfo().getLocation().x;
      int publicScreenValueY = MouseInfo.getPointerInfo().getLocation().y;
      String total = new String(publicScreenValueX + ", " + publicScreenValueY);
      return total;
      }
  return null;
    }
  }
  </code></pre>
  
  <p>How would I be able to make the project constantly update the coordinates? Could someone provide a reference on how to do this?</p>
  
  <p>Do note, this is without using a button, or without any input from the user, other than moving the mouse.</p>
  
  <p>Here is an image of what this would look like:</p>
  
  <p><a href="https://i.stack.imgur.com/Q32bW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q32bW.png" alt="Image of current program"></a></p>
  
  <p>Except the coordinates would always be updating.</p>