Use the Toolkit object to get the screen size.
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screen = kit.getScreenSize();
frame.setBounds(screen.width/4,screen.height/4, screen.width/2,
screen.height/2);
or use the frame.setLocation() method instead of setBounds()
frame.pack();
frame.setLocation((screen.width-frame.getWidth())/2, (screen.height-
frame.getHeight())/2);