Download presentation
Presentation is loading. Please wait.
Published bySolomon Higgins Modified over 9 years ago
2
Pravin Yannawar, DOCS, NMU Jalgaon
3
Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications State the restrictions on Applets State Applet Life Cycle Explain the Applet tag & its various attributes. Explain process of passing parameters to Applet State the concept of applet container and AppletContext class Explain InterApplet Communication
4
Basic Java : Applets 3 Applets Is an application designed to be transmitted over the internet & executed by a Java- compatible web browser. Are small applications that are accessed on a Internet server, transported over the Internet, automatically installed & run as part of a web document.
5
Basic Java : Applets 4 Applet Hierarchy Object Component Container Panel Applet
6
Basic Java : Applets 5 Applet Vs Applications HTML file Applet Context No main() Extend Applet class init() Flow Layout No titles Access Restrictions No HTML file Operating System main() Not necessary Constructor Border Layout Titles No Restrictions
7
Basic Java : Applets 6 Security Restrictions Applets can’t read / write files on user’s file system. Can’t communicate with an internet site other than the one that served the web page that included the applet. Can never run any executable program. All windows popped by an applet carry a warning message. Can never find any info about the local computer.
8
Basic Java : Applets 7 Applet Demo import java.awt.*; import java.applet.*; class MyApplet extends Applet { public void paint(Graphics g) { g.drawString(“Hello world”,50,50); }
9
Basic Java : Applets 8 Html Demo File My first applet
10
Basic Java : Applets 9 Converting Applications to Applets Create web page with appropriate tags to load applet code. Eliminate main() method. Replace Frame class with Applet class. Remove call to setSize() and setTitle(). Remove call to addWindowListener. Replace constructor with init() method.
11
Basic Java : Applets 10 Applet Life Cycle init() start() stop() destroy() paint(Graphics g)
12
Basic Java : Applets 11 public void init() Automatically invoked when java launches applet for the first time. Called only once. Functionality performed commonly includes: Creating the applet’s GUI. Reading values from tags. Loading off-screen images & audio clips from external files.
13
Basic Java : Applets 12 public void start() Automatically invoked after init(). Also invoked when browser browses back to applet after following a link to a diff page. Thus, code that needs to be executed repeatedly must be put in start(). E.g. Restart thread to resume an animation.
14
Basic Java : Applets 13 public void stop() Automatically invoked whenever user moves off the page on which the applet resides. Works in partnership with start().
15
Basic Java : Applets 14 public void destroy() Automatically invoked when browser no longer needs the applet. Is an applets opportunity to release any non memory resources it may have, such as threads & network connections & graphic contexts.
16
Basic Java : Applets 15 attributes CODE CODEBASE WIDTH / HEIGHT ALIGN HSPACE / VSPACE NAME tag
17
Basic Java : Applets 16 CODEBASE attribute Tells browser to search for applet class files in the directory specified by the URL.. If this attribute isn’t there, the codebase dir is assumed to be in the same dir that the HTML file resides
18
Basic Java : Applets 17 Applet(Parameter Passing) HTML FILE
19
Basic Java : Applets 18 Applet public void paint(Graphics g) { String fontName = getParameter(“font”); int fontSize = Integer.parseInt(getParameter(“size”)); g.setFont(fontName,Font.BOLD,fontSize); g.drawString(“Hey SEED !!!”,50,50); }
20
Basic Java : Applets 19 The Applet Context Is the context (browser/ applet Viewer) in which the applet runs. The getAppletContext() methods returns an object that implements an interface of the type AppletContext. This enables your applet to access features of the browser that contains it.
21
Basic Java : Applets 20 Methods of AppletContext Applet getApplet(String name): returns a handle to a named applet. AudioClip getAudioClip(URL soundFileURL): returns an audio clip object. Image getImage(URL imageFile) : returns an image. void showDocument(URL docURL) : requests the browser to display the HTML page specified in parameter.
22
Basic Java : Applets 21 InterApplet Communication Get the reference of the AppletContext Interface using the getAppletContext() method of Applet. Call the getApplet(String name) on the AppletContext which returns a reference to a named Applet. Call any method of Applet using this interface.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.