1 / 14

G6DOOS

G6DOOS. Lecture 18 Java Applets. Types of Java programs. Applications Standalone programs Applets Delivered over WWW to client (browser) Servlets Run on WWW server. Java Application. Local Computer. Bytecode (.class). Interpreter (java or jre). VM. Java Applet. Server.

Download Presentation

G6DOOS

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. G6DOOS Lecture 18 Java Applets

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

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

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

  5. 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. Basic Web Authoring and HTML • http://www.cs.nott.ac.uk/~tjb/web

  8. 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>

  9. 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

  10. 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); } }

  11. 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.

  12. 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.

  13. 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.

  14. Version Issues • AWT 1.0 - Netscape 2 - 4.06, IE 3.x & 4.0 • AWT 1.1 - Netscape 4.07-4.5+, IE 4.01 & 5.x • AWT 1.2 (Java 2 - includes Swing) • Not supported as native in Netscape 4.5 or IE 5 • Both Netscape 4.5+ and IE 5.x provide VM as a plugin - this means that they can be upgraded to support Java 2 and Swing.

More Related