- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
Java provides a large number of built-in classes, which help us in designing graphical user interface (GUI). Most of these classes belong to the package java.awt and are collectively known as Abstract Windows Toolkit (AWT).
We are familiar with software like MS-WORD, MS-EXCEL etc. All of these software have a GUI i.e. when we run these software, we see graphical user interface.
We access various features of this software by selecting different options through keyboard or mouse. Lot of programming is needed to display the user interface.
Three important parts of AWT, which help in designing graphical user interfaces, are
All of the above play an important role in designing the GUI.
Components are Java’s building blocks for creating GUI’s. A component is an object having graphical representation that can be displayed on the screen and that can interact with the user. Examples of components are the buttons, check boxes and scrollbars of a typical graphical user interface. The java.awt.Component class is the abstract super class of the non-menu related AWT components. Class component can also be extended directly to create lightweight component. A lightweight is a component that is not associated with a native opaque window.
Some components types, such as buttons and scrollbars, are used directly for GUI control. Other kinds of components (those that inherit from the Container class) provide special organization. While the components like TextField, TextArea, List etc, are used to accept input from the user. The label is a different type of component whose purpose is to simply display the appropriate label to identify other components.
Java’s components are implemented by the many subclasses of the java.awt.Component and java.awt.Menu component super classes.
One way to organize this fairly large number of classes is to divide them into categories:
- Visual components
- Container components
- Menu components
The following diagram shows AWT the component hierarchy.
The following diagram describes the container hierarchy
All the window–based applications start with a top-level window visible on the screen.
Similarly all GUI based java applications also start with a top-level window, which is referred to as top-level container in java’s terminology.
Containers are also java components that can contain other components. A component can be made visible only by adding it to a container or putting it inside a container.
All java GUI’s reside either in an applet or in a Frame. The applets and frames are the two top-level containers in java.
The applet is the top-level container for applets so the components must be added to it. Similarly the frame is the top-level component for the standalone applications.
For more complicated GUI’s it is convenient to divide the applets or frame into smaller regions. These regions might constitute, for example, a toolbar or a matrix of radio buttons. In java, GUI sub-regions are implemented most commonly with the panel container.
Panels, just like applets and frames can contain other components such as buttons, canvas, checkboxes, scrollbars, scrollpanes, text areas, textfields, and other panels.
Complicated GUI’s sometimes have very complicated containment hierarchies of panels with in panels within panels. And so on, down through many layers of containment.
As containers are also components so the methods available for components are also available for containers due to inheritance.
The most commonly used method for the containers is add() method using which the components are added the container its general form is.
void add (Component comp);
All the components are the sub-classes of the component class so any component can be added to the container using the add() method.