SlideServe
Menu
Préférences
© SlideServe · v2026

Applets

jhuskey avatar
9 diapositives · 142 Views · Jan 05, 2020

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

Applets - slide 1
01 / 9Applets
1 / 17

Télécharger la présentation

Applets
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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.