Blog

Create frame in java

Posted 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

 

 

 

 

post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter