Docsity

Java Applets: Executing Programs in Web Browsers, Schemes and Mind Maps of English

Partial preview of the text

Download Java Applets: Executing Programs in Web Browsers and more Schemes and Mind Maps English in PDF only on Docsity!

07/20/24 1

Java applets

07/20/

Introduction

Java applets are one of three kinds of Java

programs:

 An application is a standalone program that can be invoked from the command line.  An applet is a program that runs in the context of a browser session.  A servlet is a program that is invoked on a server program, and it runs in the context of a web server process.

07/20/

Applets, web page, client, server

< a pple t c o de = H e llo W o r ld. c la s s < /a pple t >

H e llo W o r ld. c la s s s e r ve r h o s t we b s e r v e r m y W e bP a g e. h t m l b r o w s e r h o s t bro ws e r re qe u s t f o r m y W e bP a g e. h t m l m y W e bP a g e. h t m l r e qu e s t f o r H e llo W o rldcla s s H e llo W o r ld. c la s s H e llo W o r ld. cla s s

07/20/

Applet Execution - 1

 An applet program is a written as a subclass of the java.Applet class or the javax.swing.Japplet class.  There is no main() method in an Applet.  An applet uses AWT for graphics, or JApplet, a subclass of javax.swing.

07/20/

Applet Execution - 3

The applet is running and rendered on

the web page.

Every Applet needs to implement one of

more of the init(), the start( ) and the

paint( ) methods.

At the end of the execution, the stop( )

method is invoked, followed by the

destroy( ) method to deallocate the

applet’s resources.

07/20/ Applet Security

For security reasons, applets that are loaded over

the network have several restrictions.

an applet cannot ordinarily read or write files

on the computer that it's executing on.

an applet cannot make network connections

except to the host that it came from.

 Ref: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html/

07/20/

HTML tags for applets - 2


< PARAM NAME ="imageSource" VALUE ="images/Beans"> < PARAM NAME ="backgroundColor" VALUE ="0xc0c0c0"> < PARAM NAME ="endImage" VALUE =10>

07/20/

The HelloWorld Applet

// applet to display a message in a window import java.awt.; import java.applet.; public class hello extends Applet { public void init( ) { setBackground(Color.yellow); } // end of init() public void paint(Graphics g) { final int FONT_SIZE = 42; Font font = new Font("Serif", Font.BOLD, FONT_SIZE); // set font, and color and display message // on the screen at position 250, g.setFont(font); g.setColor(Color.blue); // The message in the next line is the one // you will see g.drawString("Hello, world!",250,150); } // end of paint() } // end of hello

07/20/

Proxy server

A proxy server (Y) can be used to circumvent the security constraints. S e r ve r h o s t C l i e n t h o s t H TTP s e r v e r bro ws e r a pple t H o s t X a p p le t d o w n lo a d c o n n e c tio n r e q u e s t s e r v e r Y s e r v e r Z c o n n e c tio n r e q u e s t

07/20/

Summary

 An applet is a Java class  Its code is downloaded from a web server  It runs in the browser’s environment on the client host  It is invoked by a browser when it scans a web page and encounters a class specified with the APPLET tag  For security reason, the execution of an applet is normally subject to restrictions:  applets cannot access files in the file system on the client host  Applets cannot make network connection exception to the server host from which it originated