Saturday, September 17, 2011

Testing 123

import java.awt.*; public class CenterFrame // a utility class { public static Point getPosition(int frameWidth, int frameHeight) { // frame size is width * height // returns a Point holding the coordinates of // the upper left-hand corner of the (centered) frame Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension dimensions =toolkit.getScreenSize(); int x = (dimensions.width - frameWidth)/2; // x coordinate of upper left corner int y = (dimensions.height - frameHeight)/2; // y coordinate of upper left corner return (new Point(x,y)); // return coordinates as a Point object } }

No comments:

Post a Comment