tags. Due to security concerns and limited support, applets are now largely obsolete, with modern applications favoring JavaFX or standalone Java solutions."> tags. Due to security concerns and limited support, applets are now largely obsolete, with modern applications favoring JavaFX or standalone Java solutions.">
[go: up one dir, main page]

0% found this document useful (0 votes)
5 views3 pages

Java Applet Notes (1)

Java applets are embedded Java programs that run in web browsers, managed by a predefined life cycle including methods like init(), start(), and paint(). They utilize AWT for displaying content and can receive parameters via HTML <param> tags. Due to security concerns and limited support, applets are now largely obsolete, with modern applications favoring JavaFX or standalone Java solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Java Applet Notes (1)

Java applets are embedded Java programs that run in web browsers, managed by a predefined life cycle including methods like init(), start(), and paint(). They utilize AWT for displaying content and can receive parameters via HTML <param> tags. Due to security concerns and limited support, applets are now largely obsolete, with modern applications favoring JavaFX or standalone Java solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Applet - Semester Exam Notes

Java Applet Concepts

1. Applet Basics:

An applet is a special kind of Java program that is embedded in a web page and runs in the context of a

browser. Unlike standalone applications, applets do not require a main() method and are controlled by the

browser or applet viewer.

Key Features of Applets:

- Applets are subclasses of java.applet.Applet or javax.swing.JApplet.

- They are embedded in HTML pages and can be executed by a Java-enabled web browser.

- Applets have a predefined life cycle managed by the browser.

2. Applet Architecture:

The life cycle of an applet consists of the following methods:

- init(): Called once when the applet is first loaded. Used for initialization.

- start(): Called after init() and every time the applet becomes active.

- paint(Graphics g): Called whenever the applet needs to repaint itself.

- stop(): Called when the applet is no longer active but not destroyed.

- destroy(): Called when the applet is being removed from memory.

3. Applet Display Methods:

To display content on an applet, we use the AWT (Abstract Window Toolkit) methods:

- drawString(String msg, int x, int y): Displays a string on the applet.

- setForeground(Color c): Sets the text color.

- setBackground(Color c): Sets the background color.

Example:

public void paint(Graphics g) {


Java Applet - Semester Exam Notes

g.drawString("Hello, Applet!", 20, 20);

4. Passing Parameters to Applets:

Parameters can be passed to applets through HTML <param> tags.

Example HTML:

<applet code="MyApplet.class" width="300" height="200">

<param name="username" value="John">

</applet>

Java Code to Retrieve Parameter:

public void paint(Graphics g) {

String name = getParameter("username");

g.drawString("Welcome, " + name, 20, 20);

5. Sample Applet Code:

import java.applet.Applet;

import java.awt.Graphics;

public class HelloWorldApplet extends Applet {

public void paint(Graphics g) {

g.drawString("Hello World from Applet!", 20, 20);

6. Additional Notes:

- Applets run in a sandbox for security, which restricts access to the local file system.

- Applets are largely obsolete now due to security concerns and limited browser support.

- For modern applications, JavaFX or standalone Java applications are preferred.


Java Applet - Semester Exam Notes

Conclusion:

Applets were an important step in the evolution of interactive web applications in Java. Understanding their

architecture and functioning is crucial for foundational Java knowledge.

You might also like