CIS3023: Programming Fundamentals for CIS Majors II
This presentation is the property of its rightful owner.
Sponsored Links
1 / 13

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 PowerPoint PPT Presentation


  • 65 Views
  • Uploaded on
  • Presentation posted in: General

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010. Introduction to Applets. Course Lecture Slides 29 th July 2010. Ganesh Viswanathan. Applets.

Download Presentation

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cis3023 programming fundamentals for cis majors ii summer 2010

CIS3023: Programming Fundamentals for CIS Majors II

Summer 2010

Introduction to Applets

Course Lecture Slides29thJuly 2010

GaneshViswanathan


Applets

Applets

  • Applets are small applications accessed on an Internet server, transported over the networks, automatically installed and run as part of a web document.

  • At the client, applets get limited access to resources to be able to produce graphics, multimedia UI, run computations, etc. without risk of viruses or breaching data integrity.


Applets1

Applets

  • Applet Code Example: HelloWorld.java

import java.awt.Graphics;

import java.applet.Applet;

public class HelloWorldextendsApplet{

public void paint(Graphics g){

g.drawString("Hello World!", 120, 80);

}

}

Every applet must be a subclass of Applet.


Applets2

Applets

  • Web document: HelloWorld.html

<HTML>

<HEAD><TITLE>Applet example</TITLE>

</HEAD>

<BODY>

<APPLET code="HelloWorld.class" width="300px" height="200px"></APPLET>

</BODY>

</HTML>


Abstract window toolkit awt

Abstract Window Toolkit (AWT)

  • The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing, graphics, and user-interface widget toolkit.

  • Applets interact with the user through the AWT, not through the console-based I/O classes.

  • AWT is a part of Java Foundation Classes (JFC),the standard API for providing a graphical user interface (GUI) for a Java program.


Abstract window toolkit awt1

Abstract Window Toolkit (AWT)

  • AWT contains support for a window-based, graphical interface.

  • AWT supports graphics through components (visible UI elements-buttons/ labels/ textfields) and containers (components that contain and organize other components).

  • All containers inherit from the java.awt.Container base class, which itself inherits from java.awt.Component


Applets3

Applets

  • Do not have main() method

  • Instead applet begins execution when the name of its class is passed to an applet viewer or to a network browser.

  • Compile the applet in the same way as a normal java application)

  • In the example, the paint() method defined by AWT and overridden by the applet helps to redraw output on screen.


Applets4

Applets

  • Applets are event-driven.

  • User initiates interaction with an applet. These interactions are sent to the applet as “events” to which the applet must respond.

  • Example: When the user clicks on a button in the applet window, a button-click event is generated.


Applets5

Applets

  • In your applet override a set of methods that help the browser or applet-viewer to interface to the applet and control its execution.

  • Applet class defines – init(), start(), stop(), destroy()

  • AWT Component class defines paint() method.


Applet skeleton

Applet Skeleton

  • import java.awt.*;

  • import java.applet.*;

  • public class MyAppletSkeleton extends Applet {

  • // browser calls init when applet is first loaded

  • public void init( ){ /* initialization */ }

  • // called second, after init. Also called whenever applet is restarted

  • public void start( ){ /* start or resume execution */ }

  • //called when the applet is stopped

  • public void stop( ){ /* suspends execution */ }

  • //called when applet is terminated. Last method executed

  • public void destroy( ){ /* perform shutdown operations */ }

  • //called when an applet’s window must be restored (redrawn)

  • public void paint(Graphics g){ /* redisplay contents of window */ }

  • }


Applet skeleton1

Applet Skeleton

  • import java.awt.*;

  • import java.applet.*;

  • public class MyAppletSkeleton extends Applet {

  • // browser calls init when applet is first loaded

  • public void init( ){ /* initialization */ }

  • // called second, after init. Also called whenever applet is restarted.

  • public void start( ){ /* start or resume execution */ }

  • //called when the applet is stopped.

  • public void stop( ){ /* suspends execution */ }

  • //called when applet is terminated. Last method executed.

  • public void destroy( ){ /* perform shutdown operations */ }

  • //called when an applet’s window must be restored (redrawn)

  • public void paint(Graphics g){ /* redisplay contents of window */ }

  • }


Applets6

Applets

  • Further examples.


Get more info

Get more info!

  • Java docs: java.applet

  • http://download-llnw.oracle.com/javase/1.5.0/docs/api/java/applet/package-summary.html

  • Java docs: java.awt http://java.sun.com/j2se/1.5.0/docs/api/java/awt/package-summary.html

  • http://java.sun.com/products/jdk/awt/#what

  • JFC

  • http://docstore.mik.ua/orelly/java-ent/jfc/ch02_04.htm#jfcnut-ch-2-tab-awtcont


  • Login