// Creates a new JFrame with the title “JFrame title”.
JFrame frame = new JFrame(“JFrame title”);
/**
* Packs the frame such that all of the components in the
* frame is laid out.
*/
frame.pack();
// Shows the JFrame
frame.setVisible(true);
// Sets the size and location of the JFrame.
// setSize(width, height)
frame.setSize(200, 200);
// Sets the location of where the window is to show.
// setLocation(width, height)
frame.setLocation(200, 200);
/**
* You can also determine the window’s location
* by using the getX() and getY() methods, both
* of which corresponds to the X and Y coordinates.
*/
frame.getX();
frame.getY();
// You can also determine the size of the window by using
// getWidth() and getHeight();
frame.getWidth();
frame.getHeight();
// If you wanted to prevent your window
// from being resizable, you may use the setResizable(a) method,
// where ‘a’ is either ‘true’ or ‘false’.
frame.setResizable(false);
|