Javatpoint Logo
Javatpoint Logo

Frame Class in Java

A top-level window with a border and title is called a class Frame. As the default layout manager, it makes use of BorderLayout. A Windows graphics system, the java.awt.Frame component contains borders and a title bar, just like a typical GUI window. The components of default alignment added to a Java.awt.BorderLayout.

Fields of Frame:

Field Description
static float BOTTOM_ALIGNMENT Constant of ease of use for getAlignment Y
static int CROSSHAIR_CURSOR Redundant. modified by Cursor.CROSSHAIR_CURSOR
static int DEFAULT_CURSOR Redundant. modified by Cursor.DEFAULT_CURSOR.
static int HAND_CURSOR Redundant. modified by Cursor.HAND_CURSOR.
static int E_RESIZE_CURSOR Redundant. modified by Cursor.E_RESIZE_CURSOR.
static int MOVE_CURSOR Redundant. modified by Cursor.MOVE_CURSOR.
static int MAXIMIZED_HORIZ The horizontal direction of frame maximisation is indicated by this state bit.
static int MAXIMIZED_VERT The vertical direction of frame maximisation is indicated by this state bit.
static int MAXIMIZED_BOTH The frame is fully maximised (horizontally and vertically) according to this state bit mask.
static int ICONIFIED The frame is iconified, according to this state bit.
static int N_RESIZE_CURSOR Redundant. modified by Cursor.N_RESIZE_CURSOR.
static int NE_RESIZE_CURSOR Redundant. modified by Cursor.NE_RESIZE_CURSOR.
static int NORMAL Frame works in "normal" mode.
static int NW_RESIZE_CURSOR Redundant. modified by Cursor.NW_RESIZE_CURSOR.
static int S_RESIZE_CURSOR Redundant. modified by Cursor.S_RESIZE_CURSOR.
static int SE_RESIZE_CURSOR Redundant. modified by Cursor.SE_RESIZE_CURSOR.
static int SW_RESIZE_CURSOR Redundant. modified by Cursor.SW_RESIZE_CURSOR.
static int TEXT_CURSOR Redundant. modified by Cursor.TEXT_CURSOR.
static int WAIT_CURSOR Redundant. modified by Cursor.WAIT_CURSOR.

Class constructors:

Constructor Description
Frame() Creates a new, initially invisible instance of Frame.
Frame(GraphicsConfiguration gc) Creates a new Frame with the given GraphicsConfiguration that is initially invisible.
Frame(String title) Creates a new Frame object with the given title that is initially invisible.
Frame(String title, GraphicsConfiguration gc) Creates a new Frame object with the given title and GraphicsConfiguration that is initially invisible.

Class methods:

Method Description
void addNotify() Connects this Frame to a native screen resource to make it displayable.
AccessibleContext getAccessibleContext() Obtains the AccessibleContext linked to this particular Frame.
static Frame[] getFrames() Returns an array containing every Frame this application has created.
int getExtendedState() Obtains this frame's status.
int getCursorType() Redundant. Since JDK version 1.1, Component has taken its place.obtainCursor().
Image getIconImage() Returns the picture that will be used as this frame's symbol.
String getTitle() Get the frame's title.
int getState() Gets this frame's state (obsolete).
MenuBar getMenuBar() Obtains the frame's menu bar.
Rectangle getMaximizedBounds() Obtains the frame's maximised limits.
boolean isResizable() Shows whether the user may resize this frame.
void removeNotify() Breaks this Frame's link to its native screen resource, rendering it undisplayable.
void remove(MenuComponent m) Removes from this frame the given menu bar.
protected String paramString() Returns back a string that describes this Frame's current state.
boolean isUndecorated() Indicates if there are any decorations on this frame.
void setCursor(int cursorType) Redundant. Since JDK 1.1, Component.setCursor(Cursor) has taken its place.
void setMenuBar(MenuBar mb) Sets the given menu bar as the frame's menu bar.
void setMaximizedBounds(Rectangle bounds) Determines the frame's maximised limits.
void setIconImage(Image image) Sets the picture that will appear as this window's icon.
void setExtendedState(int state) Sets this frame's status.
void setResizable(boolean resizable) Determines if the user may resize this frame.
void setUndecorated(boolean undecorated) Turns on or off the frame's decorations.
void setTitle(String title) Sets the given string as this frame's title.
void setState(int state) Sets this frame's state (obsolete).

Methods inherited:

Method Inherited Description
java.awt.Window A top-level window without a menubar or borders is called a Window object. BorderLayout is the window's default layout.
java.awt.Container A component that has the ability to hold additional AWT components is known as a generic Abstract Window Toolkit (AWT) container object.
java.awt.Component An entity with a graphical representation that may interact with the user and be shown on the screen is called a component.
java.lang.Object The base of the class hierarchy is Class Object. Object is a superclass of all classes. The methods of this class are implemented by all objects, including arrays.


These steps are essentially followed while working with Frame objects in order to make a window show up on the screen.

Step 1: Construct a Frame-type object.

Step 2: Use the setSize() function to assign a size to the Frame object.

Step 3: Use the setVisible() method to make the Frame object appear on the screen.

Step 4: You must enter the code for the window closing event before you can click the close(X) button to close the window.




Frame Class in Java

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA