1 / 13

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

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

damisi
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Introduction to Applets Course Lecture Slides29thJuly 2010 GaneshViswanathan

  2. 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.

  3. 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.

  4. Applets • Web document: HelloWorld.html <HTML> <HEAD><TITLE>Applet example</TITLE> </HEAD> <BODY> <APPLET code="HelloWorld.class" width="300px" height="200px"></APPLET> </BODY> </HTML>

  5. 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.

  6. 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

  7. 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.

  8. 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.

  9. 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.

  10. 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 */ } • }

  11. 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 */ } • }

  12. Applets • Further examples.

  13. 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

More Related