Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Example Java Awt Create a Frame in Java

Related Tutorials


 
 

Share on Google+Share on Google+

Create a Frame in Java

Advertisement
In this section, you will learn how to create a frame in java awt.

Create a Frame in Java

     

Introduction

This program shows you how to create a frame in java AWT package. The frame in java works like the main window where your components (controls) are added to develop a application. In the Java AWT, top-level windows are represented by the Frame class. Java supports the look and feel and decoration for the frame. For creating java standalone application you must provide GUI to the user.

The most common method of creating a frame is by using single argument constructor of the Frame class that contains the single string argument which is the title of the window or frame. Then you can add user interface by constructing and adding different components to the container one by one.

In this program we are constructing a label to display "Welcome to Roseindia.net Tutorial." message on the frame. The center alignment of the label has been defined by the Label.CENTER. The frame initially invisible, so after creating the frame it need to visualize the frame by setVisible(true) method.

add(lbl):
This method has been used to add the label to the frame. Method add() adds a component to it's container.

setSize (width, height):
This is the method of the Frame class that sets the size of the frame or window. This method takes two arguments width (int), height (int).

setVisible(boolean):
This is also a method of the Frame class sets the visibility of the frame. The frame will be invisible if you pass the boolean value false otherwise frame will be visible.

Here is the code of the progam : 

import java.awt.*;

public class AwtFrame{
public static void main(String[] args){
Frame frm = new Frame("Java AWT Frame");
Label lbl = new Label("Welcome to Roseindia.net Tutorial.",Label.CENTER);
frm.add(lbl);
frm.setSize(400,400);
frm.setVisible(true);
  }
}

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 17, 2007

Related Tutorials

Discuss: Create a Frame in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:4
Jawahar
January 18, 2013
java applet

How to create one by one frames using one by one functions... and how to add the video files & run into the Frames...
gabbar singh
April 22, 2012
visual c++

how to create a dll file and how to use them in another module. how to link them in another file.if it is available
Thy Daro
May 4, 2012
Like to read

I like to read but don't know so this is the method that i learn from internet !
pallavi
June 21, 2012
about site

y r u put this type of ugly pictures?
DMCA.com