Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
249 views

Java JFrame

The JFrame class in Java Swing represents a top-level window container that can hold other Swing components and is used to create GUI applications; unlike the Frame class, JFrame allows setting the window closing operation and contains fields like the root pane and accessible context. JFrame examples demonstrate creating a basic window with labels and buttons by extending JFrame, adding components to a panel, setting the frame size and location, and making it visible.

Uploaded by

Kaleeswari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
249 views

Java JFrame

The JFrame class in Java Swing represents a top-level window container that can hold other Swing components and is used to create GUI applications; unlike the Frame class, JFrame allows setting the window closing operation and contains fields like the root pane and accessible context. JFrame examples demonstrate creating a basic window with labels and buttons by extending JFrame, adding components to a panel, setting the frame size and location, and making it visible.

Uploaded by

Kaleeswari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java JFrame

The javax.swing.JFrame class is a type of container which inherits the java.awt.Frame


class. JFrame works like the main window where components like labels, buttons,
textfields are added to create a GUI.

Unlike Frame, JFrame has the option to hide or close the window with the help of
setDefaultCloseOperation(int) method.

Nested Class

Modifier and Class Description


Type

protected class JFrame.AccessibleJFrame This class implements accessibility support for


the JFrame class.

Fields

Modifier and Type Field Description

protected accessibleContext The accessible context property.


AccessibleContext

static int EXIT_ON_CLOSE The exit application default window close


operation.

protected JRootPane rootPane The JRootPane instance that manages the


contentPane and optional menuBar for this
frame, as well as the glassPane.

protected boolean rootPaneCheckingEnabled If true then calls to add and setLayout will
be forwarded to the contentPane.
Constructors

Constructor Description

JFrame() It constructs a new frame that is initially invisible.

JFrame(GraphicsConfiguration gc) It creates a Frame in the specified


GraphicsConfiguration of a screen device and a blank
title.

JFrame(String title) It creates a new, initially invisible Frame with the


specified title.

JFrame(String title, It creates a JFrame with the specified title and the
GraphicsConfiguration gc) specified GraphicsConfiguration of a screen device.

JFrame Example
import java.awt.FlowLayout;  
import javax.swing.JButton;  
import javax.swing.JFrame;  
import javax.swing.JLabel;  
import javax.swing.JPanel;  
public class JFrameExample {  
    public static void main(String s[]) {  
        JFrame frame = new JFrame("JFrame Example");  
        JPanel panel = new JPanel();  
        panel.setLayout(new FlowLayout());  
        JLabel label = new JLabel("JFrame By Example");  
        JButton button = new JButton();  
        button.setText("Button");  
        panel.add(label);  
        panel.add(button);  
        frame.add(panel);  
        frame.setSize(200, 300);  
        frame.setLocationRelativeTo(null);  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        frame.setVisible(true);  
    }  
}  

Output

You might also like