apple ts

14
Applets 1

Upload: shwetasingh

Post on 19-Nov-2015

214 views

Category:

Documents


1 download

DESCRIPTION

for bca students

TRANSCRIPT

  • Applets*

  • Java AppletsApplet is a program written in the Java programming language that can be included in an HTML page and are used in Internet computing. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM).An applet is a window based program.Applets are similar to applications, but they don't run standalone. Applets are event driven.

    *

  • Applet can display graphics ,play sounds, create animation and play games.To run Java applets, you can use the Applet Viewer (included in the SDK) or any Java-compatible Web browser, such as the HotJava browser. All applets are subclasses of Applet.Applet class is contained in java. applet package.Applet contains several methods that gives the detailed control over the execution of applet.

    *

  • Difference between Application and AppletApplet do not use main() method.Applet cannot run independently.Applets cannot read or write to the file on the computer.Applets use the interface provided by AWT. (Abstract Window Toolkit)Output to the window is handled using drawString() methods.

    *

  • Every applet is implemented by creating a subclass of the Applet class.

    *

  • Life cycle of an appletLoading an Applet:An instance of the applet's controlling class (an Applet subclass) is created. The applet initializes itself. The applet starts running.

    Leaving and Returning to the Applet's Page When the user leaves the page -- for example, to go to another page -- the applet has the option of stopping itself. When the user returns to the page, the applet can start itself again. The same sequence occurs when the user iconifies and then reopens the window that contains the applet. (Other terms used instead of iconify are minaturize, minimize, and close.)

    *

  • Reloading the AppletUser reload applets, which consists of unloading the applet and then loading it again. Before an applet is unloaded, it's given the chance to stop itself and then to perform a final cleanup, so that the applet can release any resources it holds. After that, the applet is unloaded and then loaded again.

    Quitting the BrowserWhen the user quits the browser (or whatever application is displaying the applet), the applet has the chance to stop itself and do final cleanup before the browser exits.

    *

  • It can initialize itself.

    public void init() { . . . } init()a. To initialize the applet each time it's loaded (or reloaded). b. Initialize the variables, componentsc. Only once calledIt can start running.

    public void start() { . . . } start()a. To start the applet's execution, such as when the applet's loaded or when the user revisits a page that contains the applet. b. It is called each time applet is displayed on the screen.*

  • It can stop running.

    public void stop() { . . . } stop() To stop the applet's execution, such as when the user leaves the applet's page or quits the browser. We are using this to stop the thread when the applet is not visible.It can perform a final cleanup, in preparation for being unloaded.

    public void destroy() { . . . } destroy ()To perform a final cleanup in preparation for unloading.

    *

  • The Simple applet defines its onscreen appearance by overriding the paint method:public void paint(Graphics g) { . . . } The paint method is one of two display methods an applet can override: paint The basic display method. Many applets implement the paint method to draw the applet's representation within a browser page. update A method you can use along with paint to improve drawing performance.

    Note : Applets inherit their paint and update methods from the Applet class, which inherits them from the Abstract Window Toolkit (AWT) Component class. Applets inherit a group of event-handling methods from the Component class. *

  • paint() is called when the applet begins execution.When the applet must redraw its output paint() is called.It has one parameter namely Graphics which describes the graphics environment.update() default one fills up the background color and then calls paint() methodWhen the applet needs refresh repaint() is called.

    *

  • tagWhen a Java-enabled browser encounters an tag, it reserves a display area of the specified width and height for the applet, loads the bytecodes for the specified Applet subclass, creates an instance of the subclass, and then calls the instance's init and start methods. This tag tells the browser to load the applet whose Applet subclass is named AppletSubclass, displaying it in an area of the specified width and height.

    *

  • ] [< PARAM NAME = appletParameter2 VALUE = value >] . . . [alternateHTML] Tag Detail*

  • Appletcontext getAppletContext()String getAppletInfo()AudioClip getAudioClip(URL a)AudioClip getAudioClip(URL a, String b)URL getCodeBase()URL getDocumentBase()Image getImage(URL a)Image getImage(URL a,String b )String getParameter(String b)String[][] getParameterInfo()boolean isActive()void play(URL a)void play(URL a, String b)void resize( Dimension b)void resize( int width,int height)void showStatus(String str)

    *