import java.awt.Toolkit; import javax.swing.JFrame; public class WindowInTheMiddle extends JFrame {
public static void main(String[] args) {
WindowInTheMiddle window = new WindowInTheMiddle();
window.launchFrame();
} public void launchFrame() {
// The width & Height of the window
final int formWidth = 500;
final int formHeight = 500;
// The width & Height of the screen
int screenWidth = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int screenHeight = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); // Set title, size, location & visible
this.setTitle("Hello World! I'm coming!");
this.setSize(formWidth, formHeight);
this.setLocation((screenWidth-formWidth)/2, (screenHeight-formHeight)/2);
this.setVisible(true);
}
}