Unit 4 Multi Threading and Applet
Unit 4 Multi Threading and Applet
Threading
and Applets
Multi Threading
Multithreading in Java is a process of executing multiple threads
simultaneously.
running...
What if we call Java run() method directly instead start() method?
APPLICATION APPLET
(Console Application, Desktop (Embed into a Webpage)
Application)
WHAT IS APPLICATION ?
❖ It is similar to all other kind of
Programs like in C,C++, PERL etc.
to solve an problem.
❖Java Application is just like a Java
program that runs on an
underlying Operating System with
the support of a virtual machine. It
is also known as an Application
Program.
❖The Graphical User Interface is not
necessary to execute the java
applications, it can be run WITH or
WITHOUT it.
EXAMPLES OF JAVA APPLICATIONS
Graphics Ex -3
Graphics Ex -1 FREE Graphics Ex -2 STUDENT RECORD STORAGE SYSTEM
CELL GAME SWING ART (DATABASE EXAMPLE)
EXAMPLES OF JAVA APPLICATIONS
Ex #1
• Robotino Festo - Labyrinth (Java)
• https://www.youtube.com/watch?v=A6R4gcXKywo
Ex #2
• My Java Applications
• https://www.youtube.com/watch?v=pWMf9BLoIdo
Ex #3
• Sweet Home 3D
• http://www.sweethome3d.com/
BROWSER
WHAT IS APPLET ?
APPLET
INIT()
IT IS FOLLOWED BY PAINT()
WHEN APPLET IS IT IS EXECUTED WHEN APPLET IS STOPPED OR
LOADED BROWSER WINDOW IS MINIMIZED.
FOR THE FIRST TIME
START() STOP()
STOP(
)
IT IS FOLLOWED BY INIT() DESTROY()
IT IS USED TO START
APPLET PAINT(
)
PAINT() START()
IT IS USED TO DESTROY
MEMORY OCCUPIED BY APPLET.
IT IS FOLLOWED BY START()
IT IS EXECUTED APPLET WHEN BROWSER WINDOW IT IS INVOKED ONCE IN IT’S
IT IS USED TO DRAW
IS MAXIMIMED AGAIN. ENTIRE LIFE CYCLE.
ANY TEXT OR SHAPE ON APPLET
INIT() METHOD
Variable
It is the first declaration
It is Executed
method to and
on One Time in
Execute when initialization
It’s Entire Life
the Applet is operations are
Cycle.
Executed. performed in
this method.
STAGE 1
START() METHOD
It also executes
whenever the
The start() applet is
The start()
method contains restored,
method executes
the actual code maximized or
immediately after
of the applet that moving from one
the init() method.
should run. tab to another
tab in the
browser.
STAGE 2
PAINT() METHOD
The paint()
method executes
The paint()
after the
method is used
execution It can be
to redraw the
of start() method executed N
output on the
and whenever Number of Times.
applet display
the applet or
area.
browser is
resized.
STAGE 3
STOP() METHOD
The stop()
method executes
The stop() when the applet
It can be
method stops the is minimized or
executed N
execution of the when moving
Number of Times.
applet. from one tab to
another in the
browser.
STAGE 4
DESTROY() METHOD
The destroy()
method executes
stop() method
when the applet The destroy()
executes just It can be executed
window is closed method removes
before when Only 1 Time in It’s
or when the tab the applet object
destroy() method Entire Life Cycle.
containing the from memory
is invoked.
webpage is
closed.
STAGE 5
APPLET LIFE CYCLE PRACTICAL
❖ Step - 1 :: Importing the Required Package(s) for Applet to Run.
❖ Here we will define <APPLET> Tag in Comment because this file will be Compiled
by JAVA Compiler and Java Compiler won’t Understand the HTML Tags.
❖ But Still we will need to define that tag to Provide information to the Applet
Viewer.
❖ In Applet Tag we will need to define 3 Different Attributes.
❖ Code :: This Attribute contains information of the class file that has to be
read to load Applet in the Applet Viewer.
❖ Width :: This Attribute contains information of the Width of the Applet
Window that will be Displayed.
❖ Height :: This Attribute contains information of the Height of the Applet
Window that will be Displayed.
APPLET LIFE CYCLE PRACTICAL
❖ Step - 3 :: Creating an Applet Class.
❖ Here we will Create a class with Any Name and Extend it with the “APPLET”
class to create an Applet and Differentiate it will Normal Class.
❖ Note :: Your class file must be “PUBLIC” because its Object is created by Java
Plugin software that resides on the browser.
APPLET LIFE CYCLE PRACTICAL
❖ Step - 4 :: Defining Every
Method of an Applet
Class.
❖ Here we will Override the Paint method provided by “COMPONENT” Class to Draw
some Graphics(It might be any Text or any Shape) on the Screen.
❖ Methods which comes from COMPONENT class are as follows.
❖ public void paint(Graphics G) – Here paint is been overridden from
COMPONENT Class to draw something on Screen using “GRAPHICS”(Imported
from JAVA.AWT Package) class Object Named “G”.
HOW TO RUN APPLET PROGRAM
❖ Step – 1 :: Open CMD from the
Location where your APPLET
Program is Created. (As Shown
in the GIF)
{
Work APPLET VIEWER
Area
75)
Y – AXIS (0-
Assume that the Applet X – AXIS (0-
Window Size is of 200)
Width = 200
Height =75
OUTPUT DRAW STRING
PROGRAM
Scan this QR CODE for :
Y = 250
X = 125
(X,Y) = (125,250)
Work
{
APPLET VIEWER
Area
Applet Window
Size is of
Width = 200
Height =75
OUTPUT DRAW STRING
PROGRAM
Scan this QR CODE for :
Y2 = 100
Y1 = 100
X2 =
200
X1 = 100
(X1,Y1) (X2,Y2)
(100,100) (200,100)
Note :: Only Width of the Line is
Changing,
Height for Both the Points is Same So
there will No change in Y1 and Y2 Co- Full Program Source Code
ordinates. Access
GRAPHICS - DRAW RECT
EXAMPLE
(X,Y) = So this will
(20,20) be the
4th Point
{
Work APPLET VIEWER
Area
Applet Window WIDTH = 100
Size is of HEIGHT =
Width = 200 100
Height =75
OUTPUT DRAW RECT
PROGRAM
Scan this QR CODE for :
(X,Y)
(20,20) WIDTH = 100
HEIGHT = 100
{
Work APPLET VIEWER
HEIGHT = 100
Area WIDTH =
Applet Window 100
Size is of
Width = 200
Height =75
OUTPUT FILL RECT PROGRAM
Scan this QR CODE for :
(X,Y)
WIDTH =
(20,20) 100
100
HEIGHT =
X = 20 Y = 20
{
APPLET VIEWER
Work
Area
100
HEIGHT =
WIDTH =
100
Applet Window Size is
of
Width = 200
Height =75
OUTPUT DRAW OVAL
PROGRAM
Scan this QR CODE for :
Y = 20
HEIGHT = 100
X = 20 WIDTH = 100
Work
{
APPLET VIEWER
Area
100
HEIGHT =
WIDTH =
100
Applet Window
Size is of
Width = 200
Height =75
OUTPUT FILL OVAL
PROGRAM
Scan this QR CODE for :
Y = 20
100
HEIGHT =
X=
20
WIDTH =
100
Applet can only Extract Information about client-machine is its name, java
version, OS
Applets have to tag as Trusted Applets and they must be registered to APS
(Applet Security Manager)