Professional Documents
Culture Documents
GUI
GUI package and classes
GUI components and API
GUI interpeted by Asaminew G. 01/27/2023
2
GUI package
• GUI package
• Is a directory that contain all class libraries of GUI component
• Components in the java.awt package are platform dependent i.e. different appearance and
way of user interaction which is called look-and-feel in different platform
• AWT components are tied into local platform; so they are known as heavyweight
• Some of Swing components are not tied into local platform; so they are known as
lightweight. Also there are heavyweight swing component which require direct interaction
with current operating system.
GUI classes
• Super classes of swing lightweight GUI component
Object
Component
Container
Jcomponent
Cont. …
• …
Cont. …
• Class Component (package java.awt) is a subclass of Object that declares many of
the attributes and behaviors common to the GUI components in packages java.awt
and javax.swing. Most GUI components extend class Component directly or
indirectly.
Cont. …
• Jcomponent: The base class for all lightweight Swing components except top-level
containers (notice it is an abstract class)
• some Jcomponent present information or interact with the user
• some JComponents are designed to hold other components, not present or interact, they are called
Containers.
• Examples: JPanel , JScrollPane
• Top Level Windows: are containers that are not contained by any other containers;
they can be dragged and interact with the native windowing system
• Example: JFrame, JDialog (not JComponents at all)
GUI component
• AWT component :
Cont. …
• Swing components :
• Are part of java foundation classes (JFC) a java library for cross platform GUI
development. The following figure show some basic swing components
• Swing controls :- button, text box, label, check box, radio button …
…
• …
Swing component
• Swing container
• Top level :- cannot attached to other components i.e. they are stand alone
e.g. - Jframe :- An object of the class Jframe is what you think of as a window. It
automatically has a border and some basic buttons for minimizing the window and similar
actions. As you will see, a JFrame object can have buttons and many other components added
to the window and programmed for action
- Dialog
Cont. …
• Swing controls
• JButton :- is a component which a user click to trigger specific event
- is a subclass of AbstractButton
- selected or deselected
Cont. …
• JTextField :- extends class JTextComponent (javax.swing.text)
- provide single line area in which user enter text from keyboard
Cont. …
• Swing menus :-
Menu Item
Menu Bar
Menu
A given component may have any number of listeners, from zero to several listeners.
Each listener might respond to a different kind of event, or multiple listeners might
respond to the same events.
GUI : interpreted by Asaminew G. 01/27/2023
16
…
• Event handler : - the code that perform a task in respond to event
Type of an event
• Action event :- fired by component such as button, text field, password field …
- e.g.
Cont. …
• Mouse event :- fired when mouse has interaction such as : enter, released, clicked,
exited, and pressed with GUI component