To import JFrame
in Java, you will need to include the following import statement at the beginning of your code:
import javax.swing.JFrame;
JFrame
is a class in the Java Swing library, which is a set of graphical user interface (GUI) components for building Java applications. JFrame
is a top-level container that provides a window with a title bar, a border, and a content pane. You can use JFrame
to create a window that contains other GUI components, such as buttons, labels, text fields, etc.
Here is an example of how you might use JFrame
in your code to create a simple window with a title and a button:
import javax.swing.JFrame; import javax.swing.JButton; public class JFrameExample { public static void main(String[] args) { // Create a JFrame JFrame frame = new JFrame("My Window"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a button JButton button = new JButton("Click me!"); // Add the button to the content pane frame.add(button); // Set the size of the window frame.setSize(400, 300); // Make the window visible frame.setVisible(true); } }
This code creates a JFrame
with a title of "My Window", adds a button to the frame, sets the size of the window, and makes it visible. When the user clicks the close button in the title bar, the program will exit.