Home arrow Java & J2EE arrow Page 5 - Using Abstract Windowing Toolkit (AWT) In Applications

What Holds Components Together…The Container - Java

A well laid out user interface is an effective means of making applications user-friendly. It is typically used by organizations for accepting orders from customers, getting customer’s feedback on a product, for conducting a market survey on the latest trends in economy.

  1. Using Abstract Windowing Toolkit (AWT) In Applications
  2. Read On….Its Not That Abstract
  3. Your Best Buddies….Java’s AWT
  4. Features Of The Component Class
  5. What Holds Components Together…The Container
  6. How To Talk To Your Application
By: Gayathri Gokul
Rating: starstarstarstarstar / 10
September 29, 2003

print this article


Some components can also act as containers. A window for example, can be a part of another container. At the same time it can be a parent to other components, such as textbox, and a checkbox, it is a container as well. The container class is a specialized subclass of the Component class. A container may contain zero or more components. These components are called siblings, since they have the same parent window. There are three main types of containers-Window, Applet and Panel. There are two types of windows-Frame and Dialog. A frame is a rectangular box with a title and resize button. A dialog box is similar to a frame except that it cannot be resized and does not have a menu bar.

The Frame Class:
A frame is a powerful feature of AWT. You can create a window for your application using Frame class. A frame has a title bar, resizable border and an optional menu bar. You can add components to the frame using add () method as frames are derived form java.awt.container. The Border layout is the default layout of the frame. A frame receives mouse events, keyboard events and focus events.

The constructor of the Frame class receives the title of the frame as parameter. The string or name you specify will be displayed as the title of the frame.

Frame f = new Frame (“Frame Window Demo”);
After the window is created, it can be displayed by calling the setVisible () method and can be sized by calling the setSize () method. The program below displays a frame.
Import java.awt.*; Public class frame extends Frame { Public static void main (String arg[]) { Frame frm; frm = new Frame(“My First AWT Container-The Frame”); frm.setSize(300,400); frm.setBackground (Color.red); frm.setVisible(true) } }

Save the above program as frame.java, compile using Javac filename.java and execute using Java file name. The output will be a frame window with the title “My Frist AWT Container-The Frame”.

>>> More Java & J2EE Articles          >>> More By Gayathri Gokul

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: