All the GUI classes extend Component, so you can use the getWidth() and getHeight() methods to find the current dimensions of a frame or window.
Java 1.4 or newer
If you are using Java 1.4 or newer, you can use the simple method setLocationRelativeTo(null) on the dialog box, frame, or window to center it.
Java 1.3 or older
//Create a new JFrame
JFrame frame = new JFrame("Demo");
frame.setSize(400, 600);
//Calculate the frame location
int x = (screenSize.width - frame.getWidth()) / 2;
int y = (screenSize.height - frame.getHeight()) / 2;
//Set the new frame location
frame.setLocation(x, y);