Lecture - Java Applets, Swing, AWT, MVC
Lecture - Java Applets, Swing, AWT, MVC
Introduction to Java
Lecture# 10
Java AWT, Swing, MVC, Applets
Graphical User Interface
Java AWT
AWT Hierarchy
Introduction to Java Programming Language
Components
All the elements like the button, text fields, scroll bars, etc. are
called components. In Java AWT, there are classes for each
component as shown in above diagram. In order to place every
component in a particular position on a screen, we need to add
them to a container.
Container
The Container is a component in AWT that can contain another
components like buttons, textfields, labels etc. The classes that
extends Container class are known as container such as Frame,
Dialog and Panel.
It is basically a screen where the where the components are
placed at their specific locations. Thus it contains and controls the
layout of components.
Introduction to Java Programming Language
Types of containers:
There are four types of containers in Java AWT:
1.Window
2.Panel
3.Frame
4.Dialog
Introduction to Java Programming Language
Window
The window is the container that have no borders and menu
bars. You must use frame, dialog or another window for creating
a window. We need to create an instance of Window class to
create this container.
Panel
The Panel is the container that doesn't contain title bar, border
or menu bar. It is generic container for holding the components.
It can have other components like button, text field etc. An
instance of Panel class creates a container, in which we can add
components.
Frame
The Frame is the container that contain title bar and border and
can have menu bars. It can have other components like button,
text field, scrollbar etc. Frame is most widely used container
while developing an AWT application.
Introduction to Java Programming Language
Introduction to Java Programming Language
Introduction to Java Programming Language
Introduction to Java Programming Language
Java SWING
Java Swing tutorial is a part of Java Foundation Classes (JFC)
that is used to create window-based applications.
AWT vs Swing
Introduction to Java Programming Language
MVC Architecture
Hierarchy of Swing
Introduction to Java Programming Language
Java Applets
Applet is a special type of program that is embedded in
the webpage to generate the dynamic content. It runs
inside the browser and works at client side.
Advantages:
Hierarchy of Applets
Lifecycle of Applets
Introduction to Java Programming Language
Lifecycle of Applets
1.public void init(): is used to initialized the Applet. It is invoked
only once.
2.public void start(): is invoked after the init() method or
browser is maximized. It is used to start the Applet.
3.public void stop(): is used to stop the Applet. It is invoked
when Applet is stop or browser is minimized.
4.public void destroy(): is used to destroy the Applet. It is
invoked only once.
java.awt.Component class
The Component class provides 1 life cycle method of applet.
1.public void paint(Graphics g): is used to paint the Applet. It
provides Graphics class object that can be used for drawing
oval, rectangle, arc etc.
Introduction to Java Programming Language
Introduction to Java Programming Language