unit-vii - Unit-vii What is an applet? applet : a small...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Unit-vii What is an applet? applet : a small Java program that can be inserted into a web page and run by loading that page in a browser. brings web pages to life with interactive GUI, multimedia, games, and more the feature of Java that is primarily responsible for its initial popularity users can run applets simply by visiting a web page that contains an applet program Applet classes in Java Implementation a top-level container, like a Frame behaves more like a Panel class javax.swing.JApplet java.lang.Object java.awt.Component java.awt.Container java.awt.Panel java.applet.Applet javax.swing. JApplet Applet How Applets Differ from Applications Although both the Applets and stand-alone applications are Java programs, there are certain restrictions are imposed on Applets due to security concerns: Applets dont use the main() method, but when they are loaded, automatically call certain methods (init, start, paint, stop, destroy). They are embedded inside a web page and executed in browsers. Takes input through Graphical User Input ( GUI ). They cannot read from or write to the files on local computer. They cannot run any programs from the local computer. They are restricted from using libraries from other languages. The above restrictions ensures that an Applet cannot do any damage to the local system. Building Applet Code: An Example import java.awt.*; import java.applet.Applet; public class SimpleApplet extends Applet { public void paint(Graphics g) { g.drawString (A Simple Applet",20, 20); } } Begins with two import classes. java.awt.*-- required for GUI java.applet.*-- every applet you create must be a subclass of Applet, which is in java.applet package. The class should start with public , because is accessed from outside. Contd.. Applets do not begin execution at main(). An applet begins its execution when the name of its class is passed to an applet viewer or to a network browser. Compile the applet in the same way that we have been compiling programs. Running an applet involves a different process. Running an Applet There are two ways in which you can run an applet. Executing the applet within a Java-compatible browser. Using a tool called , appletviewer . An applet viewer executes your applet in a window. This is generally the fastest and easiest way to test your applet. Executing in a web browser. To execute an applet in a web browser, you need to write a short HTML file that contains a tag ( Applet ) that loads the applet. HTML file that contains a SimpleApplet <APPLET code=SimpleApplet" width=400 height=300> </APPLET> Save this file .html extension After you create this file, open your browser and then load this file, which causes SimpleApplet to be executed ....
View Full Document

Page1 / 56

unit-vii - Unit-vii What is an applet? applet : a small...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online