html5-img
1 / 9

Java Applets

Java Applets. What is Java Applet. An applet is a Java program that is referenced by a Web page and runs inside a Java-enabled Web browser.. An applet begins execution when an HTML page that "contains" it is loaded..

gates
Download Presentation

Java Applets

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

  2. What is Java Applet • An applet is a Java program that is referenced by a Web page and runs inside a Java-enabled Web browser.. • An applet begins execution when an HTML page that "contains" it is loaded.. • Either a Java-enabled Web browser or the appletviewer is required to run an applet..

  3. Applet Disadvantage • Do not read from the local (client) disk • Do not write to the local (client) disk • Do not open network connections other than to the server from which the applet was loaded • Do not link to client-side C code or call programs installed on the browser machine • Cannot discover private information about the user

  4. Applet Life Cycle • public void init() - Called when applet is first initialized • public void start() • Called immediately after init and again revisited after browser left page containing applet • Used to start animation threads • public void paint(Graphics g) • Called by the browser after init and start, and again whenever the browser redraws the screen, (typically when part of the screen has been obscured and then re exposed) • This method is where user-level drawing is placed • Inherited from java.awt.Container • public void stop() • Called when the browser leaves the page • Used to stop animation threads • public void destroy() • Called when applet is killed (rarely used)

  5. Web browser-to-applet interface

  6. Applet Template import java.applet.Applet; import java.awt.*; public class AppletTemplateextends Applet { // Variable declarations. public void init() { // Variable initializations, image loading, etc. } public void paint(Graphics g) { // Drawing operations. } }

  7. Applet HTML Template <html><head> <title>A Template for Loading Applets</title> </head> <body> <applet code="AppletTemplate.class" width=120 height=60> <b>Error! You must use a Java-enabled browser.</b> </applet> </body> </html>

  8. Applet Inheritance Hierarchy • Applet class derives from the Abstract Window Toolkit (AWT) hierarchy.

  9. AWT Pre-Made UI Components • AWT supplies the following UI components: • Buttons (java.awt.Button) • Checkboxes (java.awt.Checkbox) • Single-line text fields (java.awt.TextField) • Menus (java.awt.MenuItem) • Containers (java.awt.Panel) • Lists (java.awt.List)

More Related