Jframe Java

Share

Jframe Java

Certainly! A JFrame in Java is a top-level window that serves as the main container for building graphical user interface (GUI) applications using the Swing library. Here’s a basic example of how to create a JFrame in Java:

java
import javax.swing.*; public class MyFrame { public static void main(String[] args) { // Create a JFrame instance JFrame frame = new JFrame("My First JFrame"); // Set the size of the JFrame (width, height) frame.setSize(400, 300); // Set the default close operation to exit the application when the frame is closed frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a JLabel to add some text to the frame JLabel label = new JLabel("Hello, JFrame!"); // Add the label to the content pane of the frame frame.getContentPane().add(label); // Make the JFrame visible frame.setVisible(true); } }

In this example:

  1. We import the javax.swing.JFrame class and other necessary Swing components.

  2. We create a class called MyFrame.

  3. In the main method, we create an instance of JFrame named frame.

  4. We set the size of the JFrame using the setSize method, specifying the width and height in pixels.

  5. We set the default close operation using setDefaultCloseOperation to JFrame.EXIT_ON_CLOSE, which means the application will exit when the frame is closed.

  6. We create a JLabel with the text “Hello, JFrame!”.

  7. We add the label to the content pane of the frame using getContentPane().add(label).

  8. Finally, we make the JFrame visible with setVisible(true).

Demo Day 1 Video:

 
You can find more information about Java in this Java Docs Link

 

Conclusion:

Unogeeks is the No.1 Training Institute for Java Training. Anyone Disagree? Please drop in a comment

You can check out our other latest blogs on Java Training here – Java Blogs

You can check out our Best in Class Java Training details here – Java Training

💬 Follow & Connect with us:

———————————-

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Mail us at: info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook: https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks


Share

Leave a Reply

Your email address will not be published. Required fields are marked *