1 / 9

Applets

Applets. The objectives of this chapter are: To describe applets and their purpose To discuss embedding applets in HTML pages. What is an applet. An applet is a subclass of Panel It is a container which can hold GUI components It has a graphics context which can be used to draw images

jhuskey
Download Presentation

Applets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Applets The objectives of this chapter are: To describe applets and their purpose To discuss embedding applets in HTML pages

  2. What is an applet • An applet is a subclass of Panel • It is a container which can hold GUI components • It has a graphics context which can be used to draw images • An applet embedded within an HTML page • Applets are defined using the <applet> tag • Its size and location are defined within the tag • The browser contains a Java Virtual Machine which executes the applet • The applet .class file is downloaded, through the net, into the Virtual machine. • Unfortunately, most browsers have a very old version of the JVM • The standard is either Java 1.1.4 or 1.1.5 • Sun has released a Java 1.2 plugin which can be used instead

  3. Applications and Applets • Java applications are executed from the command line • A Java VM must be installed • The VM is given the name of a class which contains a main() method • The main method instantiates the objects necessary to start the application • Applets are executed by a browser • The browser either contains a VM or loads the Java plugin • The programmer must implement a class which is a subclass of applet • There is no main method. Instead, the applet contains an init() method which is invoked by the Browser when the applet starts

  4. HTML and Applets • The HTML applet tag contains the following parameters: • <Applet code="name of .class file" • codebase="URL where code is loaded from" • name="applet identifier" • align="LEFT|RIGHT|CENTER • width="size in pixels" • height="size in pixels“> • <param name=“aName1” value=“aValue”> • <param name=“aName2” value=“aValue”> • </Applet>

  5. Example HTML file <HTML> <HEAD> <TITLE> Sample Applet</TITLE> </HEAD> <BODY> <APPLET code="Sample.class" WIDTH=100 HEIGHT=200> This text will display if the browser does not support applets </APPLET> </BODY> </HTML>

  6. Sample Applet import java.applet.*; import java.awt.*; public class Sample extends Applet implements ActionListener { private Button okButton = new Button("OK"); private Button cancelButton = new Button("Cancel"); public void init() { okButton.addActionListener(this); cancelButton.addActionListener(this); add(okButton); add(cancelButton); } public void actionPerformed(ActionEvent x) { // ... } ... }

  7. Passing Parameters To Applets <Applet code="Menu.class“> <param name="MenuName" value="My Web Site“> <param name="Font" value="Serif"> </Applet> public class Menu extends Applet { public void init() { String menuName = getParameter("MenuName"); String theFont = getParameter("Font"); // do something with parameters } }

  8. Applet Security • Java applets execute within a Sandbox • Applets cannot access the local file system • Applets cannot connect to systems other than the server from which they were downloaded • Applets cannot listen for inbound network connections • Applets cannot spawn processes or load local jar files • Applets cannot terminate the Java VM • Applets cannot change the security policy • Signed applets can be granted more access rights • These rights are controlled by the SecurityManager

  9. Browser Issues • Unfortunately, Applets are not heavily used • Browsers support is limited • Browsers often contain outdated or buggy Java virtual machines • Each browser has its own compatibility issues. This usually means that the programmer has to implement workarounds for the various browsers • Microsoft has not been very cooperative in terms of ensuring that IE correctly implements applets. Even the Java plugin has issues under IE • Because the AWT and Swing are not highly regarded, use of Java in the client is minimal.

More Related