title: Ive been trying to get this to start in the center of the screen
body: <p>This is JavaSE-11 because i think its the latest LTS version of java and im using eclipse IDE.
  Please somebody tell me how to get this to the center of the screen on run.</p>
  <pre><code>package Main;
  
  import java.awt.Dimension;
  import java.awt.Toolkit;
  
  import javax.swing.ImageIcon;
  import javax.swing.JFrame;
  import javax.swing.WindowConstants;
  
  public class GUI extends JFrame{
      
      protected static final ImageIcon ICON = new ImageIcon(&quot;Image.png&quot;);
  
      public static void main(String[] args){
          new GUI();
      }
  
      public GUI(){
          Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
          setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
          setPreferredSize(new Dimension(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2));
          setTitle(&quot;GUI&quot;);
          setIconImage(ICON.getImage());
          pack();
          setVisible(true);
      }
  }
  </code></pre>