Chapter 02
Chapter 02
Chapter 02
CHAPTER#-02
Java Programming Chapter 02
GUI vs Non-GUI
• The classes present in the awt and swing packages can be classified into two broad categories.
GUI classes & Non-GUI Support classes.
• The GUI classes as the name indicates are visible and user can interact with them. Examples of
these are JButton, JFrame & JRadioButton etc
• The Non-GUI support classes provide services
• And perform necessary functions for GUI classes.
• They do not produce any visual output. Examples of
• these classes are Layout managers & Event
• handling(will discussed latter by another group)
Java Programming Chapter 02
AWT
AWT stands for Abstract Windowing Toolkit contains original but not pure GUI components that came with the first
release of JDK.
These components are tied directly to the local platform‘s (Windows, Linux, MAC etc)graphical user interface
capabilities. Thus results in a java program executing on different java platforms(windows, Linux, Solaris etc) has
adifferent appearance and sometimes even different user interaction on each platform.
AWT components are often called Heavy Weight Components (HWC) as they rely on the local platform‘s windowing
system.
AWT component it creates a corresponding process on the operating system.
In short component of AWT are OS depended.
Java Programming Chapter 02
Swing
These are the newest GUI components. Swing components are written, manipulated and displayed
completely in java, therefore also called pure java components. The swing components allow the
programmer to specify a uniform look and feel across all platforms.
javax.swing package is use to import not depend on operating system
99% have lightweight components
A rich set of class which contain Jpanels, Jbutton, JTextarea, ...............and so Name start from J of swing
class.
Java Programming Chapter 02
Swing vs AWT
• OS independent OS dependent
• Light weight Heavy weight
• base on Write once use Not consistent as compared to Swing
• anywhere feel and look change behavior due to os
• rich set of object less as compared to swing
Java Programming Chapter 02
Object
Component
Container
Jcomponent
Java Programming Chapter 02
Component
At the top of the AWT hierarchy is the Component class.
Components an abstract class that encapsulates all of the attributes of a visual
component.
All user interface elements that are displayed on the screen and that interact with
the user are subclasses of Component.
It defines over a hundred public methods that are responsible for managing
events, such as mouse and keyboard input, positioning and sizing the window,
and repainting.
Java Programming Chapter 02
Container
The Container class is a subclass of Component.
It has additional methods that allow other Component objects to be nested within it.
Other Container objects can be stored inside of a Container(since they are themselves instances of
Component).
This makes for a multileveled containment system.
A container is responsible for laying out (that is, positioning) Two important methods the container class
has add and set Layout.
Container are classified into two broad categories that are Top Level containers and General Purpose
Containers Top level containers can contain (add) other containers as well as basic components (buttons,
labels etc) while general purpose containers are typically used to collect basic components and are added
to top level containers.
Java Programming Chapter 02
Panel
The Panel class is a concrete subclass of Container.
It doesn’t add any new methods; it simply implements Container.
A Panel may be thought of as a recursively nestable, concrete screen component.
When screen output is directed to an Frame/applet, it is drawn on the surface of
a Panel object.
Panel is a window that does not contain a title bar, menubar, or border
Java Programming Chapter 02
Window
The Window class creates a top-level window.
A top-level window is not contained within any other object;
it sits directly on the desktop.
Generally, you won’t create Window objects directly.
Instead, you will use a subclass of Window called Frame, described next.
Java Programming Chapter 02
Frame
Frame encapsulates what is commonly thought of as a
“window.” It is a subclass of Window and has a title bar,
menu bar, borders, and resizing corners.
It contain Jlabel, textarea, button etc
in previous hierarchy we observe that JFrame is a
frame is a window. So, it can be interpreted as JFrame is a window.
Java Programming Chapter 02
Frame
Java Programming Chapter 02
Thought of Day
هرگز تسلیم نشوید ،امروز سخت است و فردا سخت
تر ،اما پس فردا روز روشنی برای تان خواهد بود