title: How to position the form in the center screen?
body: <p>I'm a .Net developer but somehow I was task to create a simple application in java for some extra reason. I was able to create that application but my problem is how can i center the form in the screen when the application is launched? </p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void formWindowActivated(java.awt.event.WindowEvent evt) 
  {
          // Get the size of the screen
          Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  
          // Determine the new location of the window
          int w = this.getSize().width;
          int h = this.getSize().height;
          int x = (dim.width-w)/2;
          int y = (dim.height-h)/2;
  
          // Move the window
          this.setLocation(x, y);
  }
  </code></pre>
  
  <p>The code above works fine but the problem is I've seen the form moving from the topleft most to center screen. I also tried adding that code in <code>formWindowOpened</code> event and still shows same action. Is there a better way for this? Just like in <code>.NET Application</code> there is a <code>CenterScreen Position</code>. Or if the code above is correct, on what Event will i put it?</p>
  
  <p>Thanks for reading this.</p>