Presentation is loading. Please wait.

Presentation is loading. Please wait.

G6DICP - Lecture 27 Java Applets.

Similar presentations


Presentation on theme: "G6DICP - Lecture 27 Java Applets."— Presentation transcript:

1 G6DICP - Lecture 27 Java Applets

2 Types of Java programs Applications Applets Servlets
Standalone programs Applets Delivered over WWW to client (browser) Servlets Run on WWW server

3 Interpreter (java or jre)
Java Application Local Computer Bytecode (.class) Interpreter (java or jre) VM

4 Java Applet Server Bytecode (.class) Client VM Web Browser

5 Web Server (eg Apache with jserv)
Java Servlet Web Server (eg Apache with jserv) Bytecode (.class) HTML VM

6 Feasibility of Applets
Java has platform independent binaries WWW is designed to be data neutral Security is the major issue

7 The HTML APPLET Tag <HTML> <HEAD>
<TITLE>An Applet Test</TITLE> </HEAD> <BODY> <H1>An Applet Test</H1> <APPLET CODE=”myApplet.class" WIDTH=360 HEIGHT=250> </APPLET> </BODY> </HTML>

8 About Applets Applets are always graphical
Applets must be subclasses of the Applet class (Panel) The Applet container is drawn in the window of the web browser. Class Applet contains the init() method Invoked automatically by a browser when a web page containing the <APPLET> tag is loaded Thus main method is not needed(!) Security issues Signed Applets - full functionality of Java Unsigned Applets - substantially restricted functionality

9 A Hello World Applet import java.awt.*; import java.applet.*;
public class demo extends Applet { public void init() setSize(360,250); } public void paint(Graphics g) g.drawString("Hello World!",50,50);

10 Typical Conversion of an Application to an Applet
Make sure that all i/o goes through the AWT interface. eg use g.drawString() instead of System.out.println() Remove any means for stopping the program eg remove System.exit() Subclass Applet instead of Frame Override the Frame.init() method, and put the functionality of the applications constructor in there. Remove the main() method of the application.

11 Applet Security Restrictions (1)
Applied by web browser (ie do not usually apply in appletviewer) Cannot use native code Cannot read some system properties Cannot start other programs Applet windows are clearly labelled - this cannot be disabled or removed.

12 Applet Security Restrictions (2)
Cannot read or write files on the client. No direct file access to the server (although network connections can be made). Network connections can only be made to the machine from which the applet is being served.

13 Version Issues Classes used must be available
This can be a problem with Swing Can be serious compatibility problems between software developed with a newer JDK and on earlier browser VM Modern browsers usually have a “plugin” VM Many older ones do not


Download ppt "G6DICP - Lecture 27 Java Applets."

Similar presentations


Ads by Google