Blog

Create frame in java

By Satyapriya Nayak Blogs | Java Sep 26, 2011
In this blog we will know how to create frame in java.

In this blog we will know how to create frame in java.

 

Frame: - This is a java application, which provide graphical user interface to accept users, and provides output in graphical way. This cannot execute in web browser. The programs execution starts from main method as stand alone application.

 

Creation process of frame

 

1.Create a class, which must inherit java.awt.frame class.

2.Create the constructor to initialize different components.

3.Change the layout of the frame if required from border layout to the required layout (flow layout, gridlayout, gridbaglayout, cardlayout).

4.Provide the paint () method to draw different shapes into the frame.

5.Initialize the class and provide size and visibility property.

 

Difference between frame and applet

 

Frame: -

1.This is a GUI for stand-alone application.

2.This cannot execute in web browser.

3.Execution starts from main () method.

4.This can access local system resources.

 

Applet: -

1.This is a GUI for web application.

2.This can executes in web browsers.

3. Execution starts from init (), start () or paint () method

4.This can access resources like (files, Dbms) of the system where it executes.

 

 

Example:-

import java.awt.*;

public class myfrm extends Frame

{

myfrm()

{

Label lab1=new Label("NORTH");

Label lab2=new Label("SOUTH");

Label lab3=new Label("EAST");

Label lab4=new Label("WEST");

Button b=new Button("CENTER");

  //BorderLayout

add(lab1,BorderLayout.NORTH);

add(lab2,BorderLayout.SOUTH);

add(lab3,BorderLayout.EAST);

add(lab4,BorderLayout.WEST);

add(b,BorderLayout.CENTER);

 

}

public static void main(String arg[])

{

 myfrm frm=new myfrm();

 frm.setSize(700,400);

 frm.setVisible(true);

 frm.setLocation(100,10);

}

}

 

Compile

Javac myfrm.java

Java myfrm

 

 

 

 

COMMENT USING