Applets 1 Applets n Design of Applets 2

  • Slides: 10
Download presentation
Applets 1

Applets 1

Applets n Design of Applets 2

Applets n Design of Applets 2

Design of Applets n Sun wrote Java to be executable within a hosting application

Design of Applets n Sun wrote Java to be executable within a hosting application n n The applications are applets. n n browser An applet is downloaded to the local client application and run on the local java-enabled machine All ordinary capability except file output and database input or output is easily available 3

Design of Applets n An Applet is run inside of another application n Browser

Design of Applets n An Applet is run inside of another application n Browser Applet. Viewer The programmer adds panels with their controls to browser’s content panel (the web page) 4

Design of Applets n There are five major methods in an Applet: n n

Design of Applets n There are five major methods in an Applet: n n n init () start () stop () destroy () paint () called called when when Applet starts page is displayed user exits resources are lost Applet is refreshed 5

Design of Applets n Sample code: public class Program 4 extends JApplet n {

Design of Applets n Sample code: public class Program 4 extends JApplet n { public void init () { get. Content. Pane ( ). add(my. Panel); } n n n } Where my. Panel is the one of the panels containing controls 6

Design of Applets n Design of Hosting Web Page (use of Applet tag) n

Design of Applets n Design of Hosting Web Page (use of Applet tag) n n n n <body> <applet code=myservlets. Adder. Applet. class width=550 height=400> <param name=host value= "http: //localhost: 8080/user 002/servlet/myservlets. Adder. Servlet"> </applet> </body> Where host is an argument sent to the Applet from the web page 7

GUI Applications n Using a frame: public class Example extends JFrame { public Example

GUI Applications n Using a frame: public class Example extends JFrame { public Example ( ) { get. Content. Pane( ). add(my. Panel); } public static void main (String args [ ]) { Example example = new Example (“Example”); example. set. Title (a. Title); example. set. Size (300, 250); example. set. Default. Close. Operation (3); example. set. Visible(true); } n } 8

GUI Application as Applet n Init and handle events public class Example extends JApplet

GUI Application as Applet n Init and handle events public class Example extends JApplet { public void init ( ) { get. Content. Pane( ). add(my. Panel); set. Title (a. Title); set. Size (300, 250); set. Default. Close. Operation (3); set. Visible(true); } n See Convert. Temperatures applet, and note change from application 9

Summary n n n Applets are a window system One can also place windows

Summary n n n Applets are a window system One can also place windows in a frame and use them in an application Applets significantly bring web-based applications to life by moving the work to the client machine n Error checking can be decentralized from the server to the clients 10