Understanding Java Applets - Basics and Functionality

Slide Note
Embed
Share

Java applets are small applications accessed and run on web clients. They do not require a main method and utilize the AWT or Swing interface. Applets can be subclassed from the Applet class and come in two types: AWT-based and Swing-based. Repainting applets can be achieved by calling the repaint() method. This summary covers the basics of Java applets, their types, essential methods for display, and information on requesting repainting.


Uploaded on Sep 12, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Applets Applets are small applications that are accessed on an Internet server, transported over the Internet, automatically installed, and run as part of a web document on client Applets do not need a main( ) method Applets must be run under an applet viewer or a Java-compatible browser Applets use the interface provided by the AWT or Swing Every applet that you create must be a subclass of Applet.

  2. Two Types of Applets First are those based directly on the Applet class, use the Abstract Window Toolkit (AWT) to provide the graphic user interface Second type of applets are those based on the Swing class JApplet. Swing applets use the Swing classes to provide the GUI. Swings offers a richer and often easier-to-use user interface than does the AWT. JApplet inherits Applet, all the features of Applet are also available in JApplet,

  3. Applet Class

  4. An Applet Skeleton

  5. First Applet program

  6. Simple Applet Display Methods void drawString(String message, int x, int y) void setBackground(Color newColor) void setForeground(Color newColor) The class Color defines the constants shown here that can be used to specify colors:

  7. Requesting Repainting How can the applet itself cause its window to be updated when its information changes? Whenever your applet needs to update the information displayed in its window, it simply calls repaint( ). The repaint( ) method is defined by the AWT. It calls applet s update( ) method, which, in its default implementation, calls paint( ).

  8. repaint( ) method void repaint( )- causes the entire window to be repainted. void repaint(int left, int top, int width, int height)- the coordinates of the upper-left corner of the region are specified by left and top, and the width and height of the region are passed in width and height.

  9. A Simple Banner Applet

  10. Using the Status Window

  11. HTML APPLET Tag

  12. Passing Parameters to Applets APPLET tag in HTML allows you to pass parameters to your applet. To retrieve a parameter, use the getParameter( ) method. It returns the value of the specified parameter in the form of a String object.

  13. getDocumentBase( ) and getCodeBase( )

Related


More Related Content