JPR 2
JPR 2
The Java Applet class is a fundamental component for creating applets in Java. Applets are small Java
programs that run inside a web browser on the client side. The Applet class provides a standard interface
between applets and their environment, offering methods for initializing, starting, stopping, and destroying the
applet. It also allows for fetching images, audio clips, and playing them. Applets have a life cycle with methods
like init, start, stop, and destroy, which control the applet's execution. The Applet class is a superclass of applets
embedded in web pages or viewed by the Java Applet Viewer. It is essential to note that the java.applet
package, including the Applet class, has been deprecated in Java 9 and later versions, and it is no longer
recommended for use.
1
Chapter 1
INTRODUCTION
In this project, aim to showcase the power of Java programming in creating interactive and dynamic
visualizations of various geometric shapes.Our applet will display a range of 2D and 3D geometric shapes,
including circles, squares, triangles, cubes, spheres, and more. Users can interact with these shapes by rotating,
scaling, and moving them around the screen, providing an engaging and immersive experience.The applet will
be developed using Java's Applet API, which allows for the creation of lightweight, platform-independent
applications that can be embedded into web pages. This makes our project accessible to a wide audience, as
users can view and interact with the shapes directly in their web browsers.In addition to displaying the shapes,
this will also provide detailed explanations and descriptions of each shape, including their mathematical
properties and formulas. This will make project not only visually engaging but also educational, helping users to
better understand the principles of geometry and Java programming.Overall, microproject on Geometric
Shapes using Java Applet aims to demonstrate the potential of Java programming in creating dynamic and
interactive visualizations, while also providing a fun and educational experience for users.
2
Chapter 2
CONCEPT
The concept of microproject is to create an interactive Java applet that allows users to explore various
geometric shapes and their properties. The applet will display a range of 2D and 3D shapes, including circles,
squares, triangles, cubes, spheres, and more.Users will be able to interact with the shapes by rotating, scaling,
and moving them around the screen, providing a hands-on and engaging experience. The applet will also
provide detailed explanations and descriptions of each shape, including their mathematical properties and
formulas.The applet will be developed using Java's Applet API, which will allow us to create a lightweight and
platform-independent application that can be embedded into web pages. This will make project accessible to a
wide audience, as users can view and interact with the shapes directly in their web browsers.In addition to
providing an interactive and educational experience, our microproject will also demonstrate the power of Java
programming in creating dynamic visualizations. In this used Java's built-in graphics and animation capabilities
to create smooth and responsive animations of the shapes, as well as to handle user input and interactions.
Overall, the concept of our microproject is to create an engaging and educational experience that showcases the
power of Java programming in creating dynamic and interactive visualizations of geometric shapes. The project
aim to provide users with a fun and interactive way to explore the world of geometry, while also demonstrating
the potential of Java programming in creating engaging and interactive applications.
APPLET
An applet is a small Java application that can be accessed on an Internet server, transported over the Internet,
and can be automatically installed and run as a part of a web document.Applets are used to create interactive
and dynamic content for web pages, such as games, animations, and calculators. They are written in the Java
programming language and run within a web browser or applet viewer that supports Java.
To run an applet, a user needs a web browser or applet viewer that supports Java. The applet is embedded in an
HTML page using the <applet> tag, which specifies the name of the applet's class file, as well as the width and
height of the applet's display area. When the HTML page is loaded, the web browser or applet viewer
downloads the applet's class file and executes it within a sandbox, which is a restricted environment that
prevents the applet from accessing sensitive system resources.
Applets can be classified as either local or remote, depending on where they are stored and how easily they can
be accessed. A local applet is created locally and kept on the local machine, and it does not need to obtain data
directly from the internet in order to function. A remote applet is stored or accessible on another computer that
is linked to the world over the internet, and it requires internet access on the system to be able to obtain and use
the applet that resides on the other machine
Local applet:-A local applet is a type of applet that is developed locally and stored on the local system. When a
webpage is trying to find a local applet, it does not require internet access to run the applet, as it is already
present on the local machine. This type of applet is beneficial as it can be easily accessed and run without the
need for an internet connection, making it more accessible for users.
Local applets are created and saved on the local system, and they do not require internet access to run, unlike
remote applets, which are stored on a remote computer connected to the internet and require internet access to
3
download and run.
Local applets are useful for situations where internet access is not available or unreliable, and they can provide
a more seamless user experience by eliminating the need to download and install applets from the internet.
Local applets are typically written in Java and can perform various functions, such as arithmetic operations,
displaying graphics, playing sounds, accepting user input, and creating animations. They are often used in
enterprise software, where they enable users to quickly access features without having to load a full app or
switch windows. Local applets can also be used in web development to add interactive elements and animations
to websites without requiring too much additional coding
Remote applet:-A remote applet is a type of Java applet that is developed and stored on a remote computer
connected to the internet, rather than on the local system. To run a remote applet, the user's system needs to be
connected to the internet so that the applet can be downloaded and executed from the remote computer.
Remote applets are designed and developed by other developers, and they can be accessed and run by users
from any location with an internet connection. This allows developers to distribute their applets to a wider
audience, without requiring users to download and install the applet on their local system. To run a remote
applet, the user must know the applet's address on the web, which is referred to as a Uniform Resource Locator
(URL). When the user navigates to a webpage that contains a remote applet, the web browser or applet viewer
sends a request to the remote computer to download the applet's class file. Once the class file is downloaded, the
web browser or applet viewer executes the applet within a sandbox, which is a restricted environment that
prevents the applet from accessing sensitive system resources.
LIFECYCLE OF AN APPLET
The life cycle of an applet involves several key stages that dictate how the applet is created, started, stopped,
and destroyed during its execution. The applet life cycle consists of five core methods: init(), start(), stop(),
paint(), and destroy(). These methods are automatically invoked by the browser to execute the applet.
Initialization : The applet's execution begins with the init() method, which is executed only once. This method
is used to initialize any variables or resources needed by the applet.
Starting: After the init() method, the start() method is invoked. It is executed when the browser is maximized
and is responsible for starting any animations or activities that the applet should perform.
Painting : The paint() method is called whenever the applet needs to be redrawn, such as when the window is
resized or when a new frame is added to an animation. It handles the visual representation of the applet.
Stopping : The stop() method is invoked when the browser is stopped, minimized, or when there is an abrupt
failure in the application. This method deals with clean-up code and suspends threads that don't need to run
when the applet is not visible.
Destroying: The destroy() method is used to destroy the application once the applet's work is done. It can be
invoked only once, and after the applet is destroyed, it cannot be restored.
5
Methods of applet life cycle
init(): The init() method is the first method to run that initializes the applet. It can be invoked only once at the
time of initialization. The web browser creates the initialized objects, i.e., the web browser (after checking the
security settings) runs the init() method within the applet.
start(): The start() method contains the actual code of the applet and starts the applet. It is invoked immediately
after the init() method is invoked. Every time the browser is loaded or refreshed, the start() method is invoked.
It is also invoked whenever the applet is maximized, restored, or moving from one tab to another in the browser.
It is in an inactive state until the init() method is invoked.
stop(): The stop() method stops the execution of the applet. The stop () method is invoked whenever the applet
is stopped, minimized, or moving from one tab to another in the browser, the stop() method is invoked. When
we go back to that page, the start() method is invoked again.
destroy(): The destroy() method destroys the applet after its work is done. It is invoked when the applet
window is closed or when the tab containing the webpage is closed. It removes the applet object from memory
and is executed only once. We cannot start the applet once it is destroyed.
paint(): The paint() method belongs to the Graphics class in Java. It is used to draw shapes like circle, square,
trapezium, etc., in the applet. It is executed after the start() method and when the browser or applet windows are
resized.
6
Packages of an applet in java
java.applet: This package provides classes for creating and managing applets. It includes the Applet class,
which is essential for developing Java applets and contains methods for the applet's life cycle, such as init(),
start(), stop(), and destroy().
Example:-import java.applet.*;
java.awt: The Abstract Window Toolkit (AWT) package contains classes for creating graphical user interfaces
in Java applets. It includes classes for creating windows, buttons, labels, text fields, and other graphical
components used in applet development.
Example:-import java.awt.*;
7
Chapter 4
METHODOLOGY
● fillPolygon():-This method fills a polygon with the specified color.
● setColor():-This method sets the current color used for drawing shapes and text.
Syntax(Color color);
Explaination:-The color parameter specifies the color to be set.
● drawString():-This method draws a string at the specified location with the specified color.
8
Chapter 5
APPLICATION OF APPLET
● Dynamic and interactive web content: Applets are used to create dynamic and interactive web
content that can respond to user input and actions.
● Enhancing website interactivity: Applets can be used to enhance the interactivity of websites by
providing interactive elements that respond to user input.
● Embedding small programs into web pages: Applets are essentially small programs that can
be embedded into web pages to make them more dynamic and entertaining.
● Animations, games, and interactive forms: Applets can be used to create animations, games,
and interactive forms that can be embedded in web pages.
● APPLET or OBJECT tags: Applets can be embedded in HTML pages using tags like APPLET or
OBJECT and hosted on web servers.
● Intranet environment: In an Intranet environment where security concerns are less stringent,
applets can still be useful for creating interactive content.
Java Web Start technology: Java Web Start technology simplifies the deployment of full-featured
Java applications over the network, offering an alternative to applets for network-based Java
applications.
9
Chapter 6
SOURCE CODE
import java.applet.*;
import java.awt.*;
// Draw a triangle
g.setColor(Color.blue);
// Draw a square
g.setColor(Color.red);
// Draw a rectangle
g.setColor(Color.green);
// Draw a circle
g.setColor(Color.orange);
g.setColor(Color.magenta);
// Draw a hexagon
g.setColor(Color.cyan);
// Draw a cube
g.setColor(Color.yellow);
// Draw a cuboid
g.setColor(Color.pink);
11
g.fillRect(400, 350, 100, 100);
// Draw a sphere
g.setColor(Color.gray);
// Draw a cylinder
g.setColor(Color.lightGray);
// Draw a cone
g.setColor(Color.darkGray);
// Draw a tetrahedron
g.setColor(Color.black);
12
g.fillPolygon(xPointsTetrahedron, yPointsTetrahedron, 4);
/*
</applet>
*/
13
Chapter 7
OUTPUT
14
CONCLUSION
To conclude the process of displaying Geometrical shapes using an applet in Java, it is essential to understand
the key aspects highlighted in the search results. Java applets, embedded in web pages, provide interactive
functionality on the client-side, allowing for dynamic content generation within a web browser. The applet
lifecycle includes methods like init(), start(), stop(), and destroy(), with the paint() method used to draw shapes
like squares and circles. Applets can be local or remote, stored locally or on a remote computer, respectively.
Running an applet involves embedding it in an HTML file using the <applet> tag or using the appletviewer tool.
Applets offer benefits like interaction with browsers and dynamic web page display. However, due to security
reasons, applets have restrictions such as limitations on file access and network connections. The use of applets
has declined over the years due to advancements in web technologies like JavaScript.
15
REFERANCE
1. Notes:-Patilmbrsm.adderess.
2.
16