How to make frame in java

We are going to discus about frame in java. In this example We have make frame in java Swing. We have created JFrame class and JFrame is an extended of java.awt.Frame.

How to make frame in java

How to make frame in java

We are going to discus about frame in java. In this example We have make frame in java Swing. We have created JFrame class and JFrame is an extended of java.awt.Frame.We have created JLabel object can display either text, an image, or both. The argument of the constructor is the title of the window or frame. We have used setVisible(true) function. The setVisible(true) function is called passing the Boolean value true.

In this below example we have used some method:-

  • setSize (400, 400):-Above method sets the size of the frame or window to width (400) and height (400) pixels.
  • setVisible(true):-Above method makes the window visible.

Example of Frame in Swing

package Frame;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class FrameExample extends JFrame{
	 private static final long serialVersionUID = 1L;
		public void start()
	    {
	        JFrame jFrame=new JFrame("Frame Tutorial");
	        JLabel l=new JLabel("Naulej Kumar(Software Devloper)");
	        jFrame.add(l);
	        jFrame.setSize(400,400);
	        jFrame.setVisible(true);
	    }
	    public static void main(String args[])
	    {
	        new FrameExample ().start();
	    }
	}

Output

Download Source Code