//Construct the application
TextEditFrame frame = new TextEditFrame();
//Pack frames that have useful preferred size info, e.g. from their layout
//Validate frames that have preset sizes
if (packFrame)
frame.pack();
else
frame.validate();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);