2. Graphical User Interface
๏ In Java, GUI-based programs are implemented by
using classes from the javax.swing and java.awt
packages.
๏ The Swing classes provide greater compatibility
across different operating systems. They are fully
implemented in Java, and behave the same on
different operating systems.
3. Various Java GUI Components
from the javax.swing package
Button
Label Text
field
Check
Box
Radio
Button
Combo Box
7. GUI Classes
๏ Can be classified into three groups
๏ Container classes
โ Ex: JFrame, JPanel, Japplet
โ To contain other components
๏ Helper classes
โ Graphics, Color, Font, etc
โ Used by components and containers to draw
and place objects
๏ Component classes
โ JButton, JTextField, ETC are subclasses of
JComponent
9. Container Classes
๏ Used to contain other GUI components
๏ Window, Panel, Frame, Dialog and Applet
are the container classes for AWT
components
๏ To work with Swing components, use
Component, Container, JFrame,
JPanel,JDialog and JApplet
๏ Container
๏ Used to group components.
๏ A layout manager is used to position and place
components in container
๏ Ex. Frames, panels and applets
10. Container Classes
๏ Jframe
๏ Is a window not contained inside another window. It
is the container that holds other swing UI
components
๏ Jpanel
๏ An invisible container that holds UI components
๏ Panel can be nested
๏ Can place panels inside a container that includes a
panel
๏ Jdialog
๏ A pop-up windows or message box to receive
additional information from the user or provide
notification that an event has occurred
๏ JApplet โ a subclass of Applet. Must extend
JApplet to create a Swing-based applet
11. GUI Helper Classes
Dimension
Font
FontMetrics
Component
Graphics
Object Color
Container
Panel Applet
Frame
Dialog
Window
JComponent
JApplet
JFrame
JDialog
Swing Components
in the javax.swing package
Lightweight
Heavyweight
Classes in the java.awt
package
1
LayoutManager
*
JPanelThe helper classes are not
subclasses of Component. They
are used to describe the
properties of GUI components
such as graphics context, colors,
fonts, and dimension.
12. Swing GUI Components
๏ Component is a superclass of all the UI
classes
๏ JComponent is a superclass of all the
lightweight Swing components
๏ JComponent is an abstract class, cannot
use new JComponent to create an
instance of Jcomponent
๏ Use the constructor of subclasses of
JComponent to create JComponent
instances.
๏ An instance of a subclass can invoke the
accessible method defined in its superclass