Advanced Java Chapter 2
Advanced Java Chapter 2
Java Applet
Types Of Java Programs
Java programs can be of two types:
Applications
Java applications are large programs that run by their own
Stand-alone programs that run without the aid of a web
browser.
Has relaxed security model since the user runs the program
locally.
Applets
Small applications that require the use of a Java enabled web
browser to run.
Applets are great for creating dynamic and interactive web
applications
Has enhanced security model since the user merely goes to a
web page and the applet runs itself.
Overview of Java Applets
The term applet refers to a little application.
In Java, an applet is a Java program that is embedded
within an HTML document and executed by a Web
browser.
You create an applet by extending the class JApplet,
which is contained in the package javax.swing.
Java Applets Vs Java Application
Unlike Java application programs, Java applets do not
have the method main.
Instead, when a browser runs an applet, the methods init,
start, and paint are guaranteed to be invoked in sequence.
Therefore, to develop an applet, all you have to do is
override one or all of the methods init, start, and paint.
Of these three methods, the paint method has one
argument, which is a Graphics object.
This allows you to use the class Graphics without actually
creating a Graphics object.
Cont…. Java Applets Vs Java Application
Creating Applet
To create Applet, all you need to do is import the package
java.awt so that you can use various methods of the class
Graphics in the paint method.
To do so, you need the following two import statements: