Java Module-5
Java Module-5
// creating a button
Button b = new Button("Click Me!!");
// no layout manager
setLayout(null);
// main method
public static void main(String args[]) {
The setBounds(int x-axis, int y-axis, int width, int height) method is used in the
above example that sets the position of the awt button.
Output:
AWT Example by Association
Let's see a simple example of AWT where we are creating instance of Frame
class. Here, we are creating a TextField, Label and Button component on the
Frame.
AWTExample2.java
// importing Java AWT class
import java.awt.*;
// creating a Frame
Frame f = new Frame();
// creating a Label
Label l = new Label("Employee id:");
// creating a Button
Button b = new Button("Submit");
// creating a TextField
TextField t = new TextField();
// main method
public static void main(String args[]) {
Output:
• Java AWT Label
• Java AWT Button
• Java AWT TextField
• Java AWT Checkbox
• Java AWT CheckboxGroup
• Java AWT Choice
• Java AWT List
• Java AWT Canvas
• AWT Scrollbar
• Java AWT MenuItem & Menu
• Java AWT PopupMenu
• Java AWT Panel
• Java AWT Toolkit
// Driver Class
public class AWT_Example {
// main function
public static void main(String[] args)
{
// Declaring a Frame and Label
Frame frame = new Frame("Basic Program");
Label label = new Label("Hello World!");
// Driver Class
public class Button_Example {
// main function
public static void main(String[] args)
{
// Creating instance of frame with the label
Frame frame = new Frame("Example 2");
Java Swing is a part of Java Foundation Classes (JFC) that is used to create
window-based applications. It is built on the top of AWT (Abstract Windowing
Toolkit) API and entirely written in java.
The javax.swing package provides classes for java swing API such as JButton,
JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.
Swing VS AWT
What is JFC
The Java Foundation Classes (JFC) are a set of GUI components which simplify
the development of desktop applications.
Hierarchy for swing components
Method Description
public void add(Component c) add a component on another component.
public void setSize(int width,int sets size of the component.
height)
public void sets the layout manager for the component.
setLayout(LayoutManager m)
public void setVisible(boolean b) sets the visibility of the component. It is by
default false.
Java Swing Examples
There are two ways to create a frame:
• By creating the object of Frame class (association)
• By extending Frame class (inheritance)
We can write the code of swing inside the main(), constructor or any other
method.
import javax.swing.*;
public class FirstSwingExample {
public static void main(String[] args) {
JFrame f=new JFrame();//creating instance of JFrame
import javax.swing.*;
public class SwingSimple {
JFrame f;
Simple(){
f=new JFrame();//creating instance of JFrame
import javax.swing.*;
public class Simple2 extends JFrame{//inheriting JFrame
JFrame f;
Simple2(){
JButton b=new JButton("click");//create button
b.setBounds(130,100,100, 40);
Panel
1 JPanel is the simplest container. It provides space in which any other
component can be placed, including other panels.
Frame
2
A JFrame is a top-level window with a title and a border.
Window
3
A JWindow object is a top-level window with no borders and no menubar.
Jframe:
The javax.swing.JFrame class is a type of container which inherits the
java.awt.Frame class. JFrame works like the main window where components
like labels, buttons, textfields are added to create a GUI.
Unlike Frame, JFrame has the option to hide or close the window with the help
of setDefaultCloseOperation(int) method.
Nested Class
Modifier and Type Class Description
The JRootPane
instance that
manages the
contentPane and
protected JRootPane rootPane
optional menuBar
for this frame, as
well as the
glassPane.
addImpl(Component
Adds the specified child
protected void comp, Object constraints,
Component.
int index)
setContentPane(Containe
Void It sets the contentPane property
contentPane)
setJMenuBar(JMenuBar
Void It sets the menubar for this frame.
menubar)
setLayeredPane(JLayeredP
Void It sets the layeredPane property.
ane layeredPane)
JFrame Example
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JFrameExample {
public static void main(String s[]) {
JFrame frame = new JFrame("JFrame Example");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JLabel label = new JLabel("JFrame By Example");
JButton button = new JButton();
button.setText("Button");
panel.add(label);
panel.add(button);
frame.add(panel);
frame.setSize(200, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Output
JApplet
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
public class EventJApplet extends JApplet implements ActionListener{
JButton b;
JTextField tf;
public void init(){
tf=new JTextField();
tf.setBounds(30,40,150,20);
b=new JButton("Click");
b.setBounds(80,150,70,40);
add(b);add(tf);
b.addActionListener(this);
setLayout(null);
}
Myapplet.html
<html>
<body>
<applet code="EventJApplet.class" width="300" height="300">
</applet>
</body>
</html>
JDialog
JDialog is a part Java swing package. The main purpose of the dialog is to add
components to it. JDialog can be customized according to user need .
Constructor of the class are:
// frame
static JFrame f;
// main class
public static void main(String[] args)
{
// create a new frame
f = new JFrame("frame");
// create a object
solve s = new solve();
// create a panel
JPanel p = new JPanel();
f.add(p);
f.show();
}
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if (s.equals("click")) {
// create a dialog Box
JDialog d = new JDialog(f, "dialog Box");
// create a label
JLabel l = new JLabel("this is a dialog box");
d.add(l);
// setsize of dialog
d.setSize(100, 100);
Output:
// frame
static JFrame f;
// dialog
static JDialog d, d1;
// main class
public static void main(String[] args)
{
// create a new frame
f = new JFrame("frame");
// create a object
solve s = new solve();
// create a panel
JPanel p = new JPanel();
f.add(p);
f.show();
}
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if (s.equals("click")) {
// create a dialog Box
d = new JDialog(f, "dialog Box");
// create a label
JLabel l = new JLabel("this is first dialog box");
// create a button
JButton b = new JButton("click me");
// create a panel
JPanel p = new JPanel();
p.add(b);
p.add(l);
// setsize of dialog
d.setSize(200, 200);
// create a label
JLabel l = new JLabel("this is second dialog box");
d1.add(l);
// setsize of dialog
d1.setSize(200, 200);
Output :
JPanel
JPanel, a part of the Java Swing package, is a container that can store a group of
components. The main task of JPanel is to organize components, various layouts
can be set in JPanel which provide better organization of components, however,
it does not have a title bar.
Constructors of JPanel
1. JPanel(): creates a new panel with a flow layout
2. JPanel(LayoutManager l): creates a new JPanel with specified
layoutManager
3. JPanel(boolean isDoubleBuffered): creates a new JPanel with a
specified buffering strategy
4. JPanel(LayoutManager l, boolean isDoubleBuffered): creates a new
JPanel with specified layoutManager and a specified buffering strategy
Commonly used Functions of JPanel
1. add(Component c): Adds a component to a specified container
2. setLayout(LayoutManager l): sets the layout of the container to the
specified layout manager
3. updateUI(): resets the UI property with a value from the current look and
feel.
4. setUI(PanelUI ui): sets the look and feel of an object that renders this
component.
5. getUI(): returns the look and feel object that renders this component.
6. paramString(): returns a string representation of this JPanel.
7. getUIClassID(): returns the name of the Look and feel class that renders
this component.
8. getAccessibleContext(): gets the AccessibleContext associated with this
JPanel.
Let us take a sample program in order to illustrate the use of JPanel class by
appending sequential execution snapshots of outputs justifying the below
program sets as follows:
Example:
// Class 1
// Helper class extending JFrame class
class solution extends JFrame {
// JFrame
static JFrame f;
// JButton
static JButton b, b1, b2;
// Main class
public static void main(String[] args)
{
// Creating a new frame to store text field and
// button
f = new JFrame("panel");
// setbackground of panel
p.setBackground(Color.red);
f.show();
}
}
Output:
Example 2:
// Main class
// Extending JFrame class
class solution extends JFrame {
// JFrame
static JFrame f;
// JButton
static JButton b, b1, b2, b3;
// setbackground of panel
p.setBackground(Color.red);
f.show();
}
}
Output:
Example 3:
// JFrame
static JFrame f;
// JButton
static JButton b, b1, b2, b3;
f.show();
}
}
Output:
JButton:
The Jbutton class is used to create a 38oolean38 button that has platform
independent implementation. The application result in some action when the
button is pushed. It inherits AbstractButton class.
Constructor Description
Jbutton() It creates a button with no
text and icon.
Jbutton(String s) It creates a button with the
specified text.
Jbutton(Icon i) It creates a button with the
specified icon object.
Methods Description
void setText(String s) It is used to set specified text
on button
String getText() It is used to return the text of
the button.
Void setEnabled(39oolean b) It is used to enable or disable
the button.
Void setIcon(Icon b) It is used to set the specified
Icon on the button.
Icon getIcon() It is used to get the Icon of
the button.
Void setMnemonic(int a) It is used to set the
mnemonic on the button.
Void addActionListener(ActionListener a) It is used to add the action
listener to this object.
JLabel
Java JLabel
The object of JLabel class is a component for placing text in a container. It is
used to display a single line of read only text. The text can be changed by an
application but a user cannot edit it directly. It inherits JComponent class.
1. import javax.swing.*;
2. class LabelExample
3. {
4. public static void main(String args[])
5. {
6. JFrame f= new JFrame("Label Example");
7. JLabel l1,l2;
8. l1=new JLabel("First Label.");
9. l1.setBounds(50,50, 100,30);
10. l2=new JLabel("Second Label.");
11. l2.setBounds(50,100, 100,30);
12. f.add(l1); f.add(l2);
13. f.setSize(300,300);
14. f.setLayout(null);
15. f.setVisible(true);
16. }
17. }
Output:
Java JLabel Example with ActionListener
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class LabelExample extends Frame implements ActionListener{
JTextField tf; JLabel l; JButton b;
LabelExample(){
tf=new JTextField();
tf.setBounds(50,50, 150,20);
l=new JLabel();
l.setBounds(50,100, 250,20);
b=new JButton("Find IP");
b.setBounds(50,150,95,30);
b.addActionListener(this);
add(b);add(tf);add(l);
setSize(400,400);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
try{
String host=tf.getText();
String ip=java.net.InetAddress.getByName(host).getHostAddress();
l.setText("IP of "+host+" is: "+ip);
}catch(Exception ex){System.out.println(ex);}
}
public static void main(String[] args) {
new LabelExample();
}}
Output:
JTextField
Java JTextField
The object of a JTextField class is a text component that allows the editing of a
single line text. It inherits JTextComponent class.
JTextField class declaration
Let's see the declaration for javax.swing.JTextField class.
1. public class JTextField extends JTextComponent implements SwingCon
stants
Commonly used Constructors:
Constructor Description
JTextArea
Java JTextArea
The object of a JTextArea class is a multi line region that displays text. It allows
the editing of multiple line text. It inherits JTextComponent class
JTextArea class declaration
Let's see the declaration for javax.swing.JTextArea class.
1. public class JTextArea extends JTextComponent
Commonly used Constructors:
Constructor Description
Creates a text area that displays
JTextArea()
no text initially.
Java JPasswordField
The object of a JPasswordField class is a text component specialized for
password entry. It allows the editing of a single line of text. It inherits
JTextField class.
Layout Management
BorderLayout (LayoutManagers)
Java LayoutManagers
The LayoutManagers are used to arrange components in a particular manner.
The Java LayoutManagers facilitates us to control the positioning and size of
the components in GUI forms. LayoutManager is an interface that is
implemented by all the classes of layout managers. There are the following
classes that represent the layout managers:
1. java.awt.BorderLayout
2. java.awt.FlowLayout
3. java.awt.GridLayout
4. java.awt.CardLayout
5. java.awt.GridBagLayout
6. javax.swing.BoxLayout
7. javax.swing.GroupLayout
8. javax.swing.ScrollPaneLayout
9. javax.swing.SpringLayout etc.
Java BorderLayout
The BorderLayout is used to arrange the components in five regions: north,
south, east, west, and center. Each region (area) may contain one component
only. It is the default layout of a frame or window. The BorderLayout provides
five constants for each region:
1. public static final int NORTH
2. public static final int SOUTH
3. public static final int EAST
4. public static final int WEST
5. public static final int CENTER
Constructors of BorderLayout class:
o BorderLayout(): creates a border layout but with no gaps between the
components.
o BorderLayout(int hgap, int vgap): creates a border layout with the
given horizontal and vertical gaps between the components.
Example of BorderLayout class: Using BorderLayout() constructor
FileName: Border.java
import java.awt.*;
import javax.swing.*;
// creating buttons
JButton b1 = new JButton("NORTH");; // the button will be labeled as
NORTH
JButton b2 = new JButton("SOUTH");; // the button will be labeled as
SOUTH
JButton b3 = new JButton("EAST");; // the button will be labeled as E
AST
JButton b4 = new JButton("WEST");; // the button will be labeled as
WEST
JButton b5 = new JButton("CENTER");; // the button will be labeled a
s CENTER
f.setSize(300, 300);
f.setVisible(true);
}
public static void main(String[] args) {
new Border();
}
}
Output:
// constructor
BorderLayoutWithoutRegionExample()
{
jframe = new JFrame();
jframe.setSize(300,300);
jframe.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new BorderLayoutWithoutRegionExample();
}
}
Output:
Border
Java GridLayout
The Java GridLayout class is used to arrange the components in a rectangular
grid. One component is displayed in each rectangle.
Constructors of GridLayout class
1. GridLayout(): creates a grid layout with one column per component in a
row.
2. GridLayout(int rows, int columns): creates a grid layout with the given
rows and columns but no gaps between the components.
3. GridLayout(int rows, int columns, int hgap, int vgap): creates a grid
layout with the given rows and columns along with given horizontal and
vertical gaps.
Example of GridLayout class: Using GridLayout() Constructor
The GridLayout() constructor creates only one row. The following example
shows the usage of the parameterless constructor.
FileName: GridLayoutExample.java
// import statements
import java.awt.*;
import javax.swing.*;
public class GridLayoutExample
{
JFrame frameObj;
// constructor
GridLayoutExample()
{
frameObj = new JFrame();
// creating 9 buttons
JButton btn1 = new JButton("1");
JButton btn2 = new JButton("2");
JButton btn3 = new JButton("3");
JButton btn4 = new JButton("4");
JButton btn5 = new JButton("5");
JButton btn6 = new JButton("6");
JButton btn7 = new JButton("7");
JButton btn8 = new JButton("8");
JButton btn9 = new JButton("9");
frameObj.setSize(300, 300);
frameObj.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new GridLayoutExample();
}
}
Output:
Example of GridLayout class: Using GridLayout(int rows, int columns)
Constructor
FileName: MyGridLayout.java
import java.awt.*;
import javax.swing.*;
public class MyGridLayout{
JFrame f;
MyGridLayout(){
f=new JFrame();
JButton b1=new JButton("1");
JButton b2=new JButton("2");
JButton b3=new JButton("3");
JButton b4=new JButton("4");
JButton b5=new JButton("5");
JButton b6=new JButton("6");
JButton b7=new JButton("7");
JButton b8=new JButton("8");
JButton b9=new JButton("9");
// adding buttons to the frame
f.add(b1); f.add(b2); f.add(b3);
f.add(b4); f.add(b5); f.add(b6);
f.add(b7); f.add(b8); f.add(b9);
JFrame frameObj;
// constructor
GridLayoutExample1()
{
frameObj = new JFrame();
// creating 9 buttons
JButton btn1 = new JButton("1");
JButton btn2 = new JButton("2");
JButton btn3 = new JButton("3");
JButton btn4 = new JButton("4");
JButton btn5 = new JButton("5");
JButton btn6 = new JButton("6");
JButton btn7 = new JButton("7");
JButton btn8 = new JButton("8");
JButton btn9 = new JButton("9");
JFrame frameObj;
// constructor
FlowLayoutExample()
{
// creating a frame object
frameObj = new JFrame();
frameObj.setSize(300, 300);
frameObj.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new FlowLayoutExample();
}
}
Output:
f.setSize(300,300);
f.setVisible(true);
}
public static void main(String[] args) {
new MyFlowLayout();
}
}
Output:
Example of FlowLayout class: Using FlowLayout(int align, int hgap, int vgap)
constructor
FileName: FlowLayoutExample1.java
// import statement
import java.awt.*;
import javax.swing.*;
// constructor
FlowLayoutExample1()
{
// creating a frame object
frameObj = new JFrame();
frameObj.setSize(300, 300);
frameObj.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new FlowLayoutExample1();
}
}
Output:
Java BoxLayout
The Java BoxLayout class is used to arrange the components either vertically
or horizontally. For this purpose, the BoxLayout class provides four constants.
They are as follows:
Note: The BoxLayout class is found in javax.swing package.
Fields of BoxLayout Class
1. public static final int X_AXIS: Alignment of the components are
horizontal from left to right.
2. public static final int Y_AXIS: Alignment of the components are
vertical from top to bottom.
3. public static final int LINE_AXIS: Alignment of the components is
similar to the way words are aligned in a line, which is based on the
ComponentOrientation property of the container. If the
ComponentOrientation property of the container is horizontal, then the
components are aligned horizontally; otherwise, the components are
aligned vertically. For horizontal orientations, we have two cases: left to
right, and right to left. If the value ComponentOrientation property of the
container is from left to right, then the components are rendered from left
to right, and for right to left, the rendering of components is also from
right to left. In the case of vertical orientations, the components are
always rendered from top to bottom.
4. public static final int PAGE_AXIS: Alignment of the components is
similar to the way text lines are put on a page, which is based on the
ComponentOrientation property of the container. If the
ComponentOrientation property of the container is horizontal, then
components are aligned vertically; otherwise, the components are aligned
horizontally. For horizontal orientations, we have two cases: left to right,
and right to left. If the value ComponentOrientation property of the
container is also from left to right, then the components are rendered from
left to right, and for right to left, the rendering of components is from
right to left. In the case of vertical orientations, the components are
always rendered from top to bottom.
Constructor of BoxLayout class
1. BoxLayout(Container c, int axis): creates a box layout that arranges the
components with the given axis.
Example of BoxLayout class with Y-AXIS:
FileName: BoxLayoutExample1.java
import java.awt.*;
import javax.swing.*;
public BoxLayoutExample1 () {
buttons = new Button [5];
public BoxLayoutExample2() {
buttons = new Button [5];
// main method
public static void main(String argvs[])
{
// creating an object of the class BoxLayoutExample3
BoxLayoutExample3 obj = new BoxLayoutExample3();
}
}
Output:
Example of BoxLayout Class with PAGE_AXIS
The following example shows how to use PAGE_AXIS.
FileName: BoxLayoutExample4.java
// import statements
import java.awt.*;
import javax.swing.*;
constrntObj.fill = GridBagConstraints.VERTICAL;
for (int i = 0; i < 5; i++)
{
buttons[i] = new Button ("Button " + (i + 1));
// the components will be displayed just like the line is present on a page
setLayout (new BoxLayout(this, BoxLayout.PAGE_AXIS));
setSize(400, 400);
setVisible(true);
}
// main method
public static void main(String argvs[])
{
// creating an object of the class BoxLayoutExample4
BoxLayoutExample4 obj = new BoxLayoutExample4();
}
}
Output:
The above output shows that the buttons are aligned horizontally. Now, we will
display the buttons vertically using the PAGE_AXIS.
FileName: BoxLayoutExample5.java
// import statementss
import java.awt.*;
import javax.swing.*;
f.setSize(400, 400);
f.setVisible(true);
}
// main method
public static void main(String argvs[])
{
// creating an object of the class BoxLayoutExample5
BoxLayoutExample5 obj = new BoxLayoutExample5();
}
}
Output:
Applets
Java Applet
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.
Advantage of Applet
There are many advantages of applet. They are as follows:
Do You Know
o Who is responsible to manage the life cycle of an applet ?
o How to perform animation in applet ?
o How to paint like paint brush in applet ?
o How to display digital clock in applet ?
o How to display analog clock in applet ?
o How to communicate two applets ?
Hierarchy of Applet
As displayed in the above diagram, Applet class extends Panel. Panel class extends Container
subclass of Component.
}
Note: class must be public because its object is created by Java Plugin software
that resides on the browser.
myapplet.html
<html>
<body>
<applet code="First.class" width="300" height="300">
</applet>
</body>
</html>
}
/*
<applet code="First.class" width="300" height="300">
</applet>
*/
To execute the applet by appletviewer tool, write in command prompt:
c:\>javac First.java
c:\>appletviewer First.java
import java.applet.Applet;
import java.awt.*;
g.setColor(Color.pink);
g.fillOval(170,200,30,30);
g.drawArc(90,150,30,30,30,270);
g.fillArc(270,150,30,30,0,180);
}
}
myapplet.html
<html>
<body>
<applet code="GraphicsDemo.class" width="300" height="300">
</applet>
</body>
</html>
An applet is a Java program that can be embedded into a web page. It runs
inside the web browser and works on the client-side. An applet is embedded
in an HTML page using the APPLET or OBJECT tag and hosted on a web
server. The entire life cycle of an applet is managed by the Applet
Container. All applets are sub-classes (either directly or indirectly) of
java.applet.Applet class. Applets are not stand-alone programs. They run
either within a web browser or an applet viewer.
Note:
Java applet is deprecated because it’s no longer widely used on the web. The
popularity of applets has decreased over the years as browser support for
applets has declined, and more advanced technologies such as web-based
applications and JavaScript have become more prevalent. Additionally,
applets are considered a security risk as they can execute arbitrary code on
the client machine, and many browsers now disable them by default. As a
result, Java’s applet technology is no longer seen as a valuable feature for
Java developers and is removed from the newer versions of Java.
• Applets generate Dynamic content
• Applets work on the client-side
• The response time is fast
We can view our Applet with the help of a standard applet viewer tool
called Applet Viewer. Unlike the general executions and outputs of the java
programs, applet execution does not begin at main() method, and the
output of an applet window is not catered by System.out.println(). Rather it
is handled with various Abstract Window Toolkit (AWT) methods, such as
drawString().
Let us do see a hierarchy of Applet before landing up on stages in the
lifecycle of the java applet that is as follows in the below media:
All these are available in AWT Package java.awt.applet.* and in order ton
import paint (Graphics g) we do use java.awt.component package
Let’s understand each method in a detailed manner :
Method 1: init()
• This is the first method to be called
• Variables can be initialized here
• This method can be called only once during the run time of the applet
• It is invoked at the time of Initialization
Syntax:
public void init()
{
// To initialize objects
}
Method 2: start()
• This method is called after init() method
• start() method is used for starting the applet
• It is also called to restart an applet after it has been stopped. i.e. to
resume the applet
Syntax:
public void start()
{
// To start the applet code
}
Note: init() is called once i.e. when the first time an applet is loaded whereas
start( ) is called each time an applet’s HTML document is displayed onscreen.
Method 3: paint()
void paint(Graphics g){ }
• paint() method is used for painting any shapes like square, rectangle,
trapeziums, etc.
• paint() method has one parameter of type Graphics Class, this
Graphics class enables the painting features in an applet.
• This parameter will contain the graphics context, which is used
whenever output for the applet is required.
Syntax:
public void paint(Graphics graphics)
{
// Any shape's code
}
Note: This is the only method among all the method mention above, which is
parameterized.
Method 4: stop()
• It is invoked every time the browser is stopped, minimized or when
there is an abrupt failure in the application.
• After stop()method called, we can also use start() method whenever
we want.
• This method mainly deals with clean up code.
• The stop( ) method is called when a web browser leaves the HTML
document containing the applet when it goes to another page, for
example, when stop( ) is called, the applet is probably running. You
should use stop( ) to suspend threads that don’t need to run when the
applet is not visible. You can restart them when start( ) is called if the
user returns to the page.
Syntax:
public void stop()
{
// To stop the applet code
}
Method 5: destroy()
• destroy() method is used to destroy the application once we are done
with our applet work. It can be invoked only once.
• Once applet is destroyed we can’t start() the applet (we cannot
restore the applet again)
• The destroy( ) method is called when the environment determines
that your applet needs to be removed completely from memory.
Syntax:
public void destroy()
{
// To destroy the applet
}
Note: The stop( ) method is always called before destroy( )
Syntax: Entire Applet Life Cycle