Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Create JFrame in java with example

    • 0
    • 2
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 230
    Comment on it

    JFrame is class of swing package in java and swing package is a part of j2se to develop standalone application.

    Here below I am Creating a frame with single argument constructor of the JFrame where I have declared the title of the frame. Next, I am creating a JPanel, JPanel is another type of container. in which panel we are adding other components and the panel itself will be added to the frame.

    package com.findnerd;
    import java.awt.FlowLayout;
    import javax.swing.*;
    public class TestFrameExample {
    
        public static void main(String s[]) {
    
            JFrame frame = new JFrame("JFrame Example");
    
            JPanel panel = new JPanel();
            panel.setLayout(new FlowLayout());
            JLabel label = new JLabel("This is a label! Bhagwan Singh");
            JButton button = new JButton();
            button.setText("Press me");
    
            panel.add(label);
            panel.add(button);
            frame.add(panel);
    
            frame.setSize(300, 300);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
     }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: