Java Applets

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Java Applets as PDF for free.

More details

  • Words: 604
  • Pages: 20
Name: Richa Sharma PRN: 060341044 Subject: WDT Presentation

 Applet: Special kind of java program that a Javaenabled browser can download from internet and then run.

 Hopes: Hopes Users can access their s/w from any java enabled computer or device with an internet connection.



Html: (used to describe layout of a web page) simply a vehicle to indicate elements of a hypertext page.



“How to use Applets in a web page?” The html page uses a tag that tells the browser the following: 3. Where to get the class file… 4. How the applet is positioned on the web page(size,location,etc)… 



The Browser then retrieves the class files from the internet and automatically runs the applet,using an JRE or JVM.



In addition to the applet itself,the web can have other html element on web pages(multiple fonts,bulleted lists,graphics,links..)..



Thus, Java applet is not a tool for designing html pages,it is a tool for ‘bringing them to life’..

A Bit of History… Initially Sun’s Hot Java browser required.. Netscape followed by IE include a JVM.. Problem: inability to adapt to new versions…  Solution:

Sun’s “Java plug-in” tool.  Installation of the current version: http://java.sun.com/getjava

An applet is simply a ‘java class’ that extends the java.applet.Applet class. Although applet is an AWT component,we generally use SWING to implement applets: So,applets are made to extend ‘JApplet’,the super class for swing applets.

/* The following HTML tags are required to display this applet in a browser */ import javax.swing.*; public class NotHelloWorldApplet extends Japplet { public void init() { JLabel label = new JLabel("Not a Hello,Worldapplet",SwingConstants.CENTER); add(label); } }

To execute the applet,we can carry out the following: Compile your java source files into class files. Create an HTML file that tells the browser which class file to load first and how to size the applet.



In ‘appletviewer’.



In a browser.



Is a part of JDK that helps in testing of the web page before loading it on the net.



At the command line,we give the following: appletviewer NotHelloWorldApplet.html

To get hold of user’s perspective. The real view. You need: 1. Java 2 enabled browser. 2. To load the html file into the browser

The NotHelloWorldApplet.java looks like:

 Code: tells the browser how to locate the applet.  Width, height: size the window holding the applet.

The when called,what it does and action examples of: Public void init( ):  Applet loaded for execution.  Initializes the applet.  Processing parameter values,adding user interface components.

Public void start( ):  After init completes execution.  User moves to some other site & later return to the applet’s html page.  Starting animation,threads of execution.

Public void paint(Graphics g):  after init and start.  When applet needs to be repainted.  Drawing with graphics object g that is passed to the paint method by the

applet container.

Public void stop( ):  User leaves applet page.  Tasks required to suspend the applet execution.  Stops execution of animation,threads etc.

Public void destroy( ):  Applet being removed from memory.  User exits browsing session.  Clean up all resources allocated to the applet.

Sand box security model: “code executing in the ‘sandbox’ is not allowed to ‘play outside the sandbox’. Some important sites:  For applets resources:

java.sun.comjar  For some of the best applets on net:

www.jars.com

Summary … Applet and basics. History. The inheritance hierarchy. An example. Execution of applet. Applet viewing Html tags and attributes Applet life cycle methods. Some sites.

Thank you…

Related Documents

Java Applets
October 2019 10
Applets
May 2020 9
Applets
November 2019 17
Applets
June 2020 7