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
    • 236
    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.

    1. package com.findnerd;
    2. import java.awt.FlowLayout;
    3. import javax.swing.*;
    4. public class TestFrameExample {
    5.  
    6. public static void main(String s[]) {
    7.  
    8. JFrame frame = new JFrame("JFrame Example");
    9.  
    10. JPanel panel = new JPanel();
    11. panel.setLayout(new FlowLayout());
    12. JLabel label = new JLabel("This is a label! Bhagwan Singh");
    13. JButton button = new JButton();
    14. button.setText("Press me");
    15.  
    16. panel.add(label);
    17. panel.add(button);
    18. frame.add(panel);
    19.  
    20. frame.setSize(300, 300);
    21. frame.setLocationRelativeTo(null);
    22. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    23. frame.setVisible(true);
    24. }
    25. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: