Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Create a Frame in Java 
 

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.

                         

» View all related tutorials
Related Tags: c class make method sed boolean value ole set oo frame if boo to ram bool argument e il not

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

i wrote the program to create the awt frame,errrs came,can not find the symbol ,method
setSize(400,400);

Posted by sri on Monday, 09.22.08 @ 18:47pm | #80605

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.