Thursday, 15 January 2015

Filled Under:

How to create simple j frame in java

There are two methods of creating j frame in java in first method frame is created by creating constructor and in second method frame is created by creating object of Jframe class.

WHAT IS CONSTRUCTOR IN JAVA:

Constructor is used to initialize the object for example here we are using it to initialize the frame object.

 SETTITLE METHOD IN JAVA:

This method is used to give title to a frame

SETVISIBLE METHOD IN JAVA:

In easy word we can say that this method is to show or disappear  something if we set setisible(false) then window will disappear 

SETSIZE METHOD IN JAVA:

Setsize method set the size of a window it's depend upon user how much size he sets, 

METHOD 1:

import javax.swing.JFrame;

 class myjframe1 extends JFrame 
{

  public myjframe1()
 {

  setTitle("Simple example");
  setSize(300, 200);
  setVisible(true);
 setDefaultCloseOperation(EXIT_ON_CLOSE);      
  }
}
class simpframe
{
public static void main(String args[])
{
myjframe1 x= new myjframe1();
}
}

METHOD 2:

import javax.swing.JFrame;

public class myjframe extends JFrame 
{

public static void main(String args[])
{

JFrame myFrame = new JFrame("This is my frame");

myFrame.setSize(500,400);

myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

myFrame.setVisible(true);

}

}

OUTPUT:




0 comments:

Post a Comment