JFrame is a class in the Java Swing library that represents a window, or a frame, that can be used to display graphical user interfaces (GUIs). It provides a container for other GUI components, such as buttons, labels, text fields, etc., and handles events, such as mouse clicks or keyboard inputs.

To use JFrame, you need to create an instance of the class and set it up with the desired layout and components. Here's a basic example of creating and displaying a JFrame:

import javax.swing.JFrame;

public class MyFrame extends JFrame {
    public MyFrame() {
        // Set the frame title
        setTitle('My JFrame');

        // Set the frame size
        setSize(400, 300);

        // Set the default close operation
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Add components or customize the frame further

        // Display the frame
        setVisible(true);
    }

    public static void main(String[] args) {
        // Create an instance of MyFrame
        MyFrame frame = new MyFrame();
    }
}

In this example, we create a subclass of JFrame called 'MyFrame' that extends the functionality of the JFrame class. In the constructor, we set the title, size, and default close operation of the frame. You can add more components or customize the frame further based on your requirements. Finally, we call the setVisible(true) method to make the frame visible on the screen.

Note that the main method is used to create an instance of the MyFrame class and start the application.

JFrame: Java Swing Window Creation Tutorial

原文地址: https://www.cveoy.top/t/topic/pPnz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录