import java.awt.*;
import javax.swing.*;
public class ShowCenter extends JFrame {
public static void main(String[] args) {
final ShowCenter window = new ShowCenter();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(300, 100);
//The following code ensure the window shown on the center of screen.
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
window.setLocation((dim.width - window.getWidth()) / 2, (dim.height - window.getHeight()) / 2);
window.setVisible(true);
}
});
}
}