![]() |
VOOZH | about |
Applets are tiny Java programs that can be installed and run automatically as part of a web page. They can be viewed on an Internet server, transmitted over the Internet, and installed and run automatically as part of a web document or desktop application.
Note:
Java applet is deprecated, which means it's no longer recommended for use and may be removed in future versions of the language. However, it is still supported in current versions of Java. As applets are no longer widely used, Java developers are encouraged to use alternative technologies such as web-based applications or JavaScript. Nevertheless, the applet technology is still available for those who need it, but it's not recommended for new projects. There are two standard methods for running an applet:
Let's understand each technique one by one
Suppose we have a GfgApplet.java file in which we have our java code.
To run an applet in a web browser, we must create an HTML text file with a tag that loads the applet. For this, we may use the APPLET or OBJECT tags. Here is the HTML file that runs HelloWorld with APPLET:
Attributes in applet tag:
GfgApplet.html
<html> <body> <applet code="GfgApplet.class" width=300 height=100></applet> </body> </html>
Output on browser:
The applet GfgApplet.class is loaded into the browser when you access GfgApplet.html.
To load applet programs, the browser must have java enabled.
It is a java application that allows you to view applets. It's similar to a mini-browser that will enable you to see how an applet might appear in a browser. It recognizes the APPLET tag and uses it during the creation process. The APPLET tag should be written in the source code file, with comments around it.
To use the applet viewer utility to run the applet, type the following at the command prompt:
c:\>javac GfgApplet.java c:\>appletviewer GfgApplet.java
Output: