AZK BG Java Applets

  1. applets are -
    are small programs that are designed for transmission over the Internet and run within a browser
  2. applets provide -
    secure way to dynamically download and execute programs over the Web
  3. There are 2 varieties of applets based on:
    • 1) AWT - Abstract Window Toolkit
    •     - is original GUI toolkit
    • 2) Swing
    •     - is lightweight alternative GUI that is built on top of the AWT
  4. AWT
    • - Abstract Window Toolkit
    • - is original GUI toolkit
  5. Swing
    • - is built on top of the AWT
    • - is lightweight alternative GUI
  6. AWT Aplet code:
    • import java.applet.*;
    • import java.awt.*;

    • /*
    • <applet code="BG_515_410_Applet_Basics" width=200 height=60>
    • </applet>
    • */

    • public class BG_515_410_Applet_Basics extends Applet {
    •    public void paint(Graphics g){
    •       g.drawString("Java makes applet easy", 20, 20);
    •    }
    • }
  7. import java.awt.*;
    • - AWT-based applets
    • - awt - Abstract Window Toolkit classes
    • - AWT contains support for a limited window-based, graphical user interface
  8. import java.applet.*;
    • - AWT-based applets
    • - contains the class Applet
    • - Every AWT-based applet that must be a subclass of Applet (extends Applet).
  9. Hierarchy For Package java.applet
    • java.lang.Object
    •    javax.accessibility.AccessibleContext
    •       java.awt.Component.AccessibleAWTComponent
    •          java.awt.Container.AccessibleAWTContainer
    •             java.awt.Panel.AccessibleAWTPanel
    •                java.applet.Applet.AccessibleApplet
    •    java.awt.Component
    •       void paint(Graphics g) - Paints this component. 
    •       java.awt.Container
    •          java.awt.Panel
    •             java.applet.Applet
  10. class to process Applet
    • public class Applet_Basics extends Applet {
    •    - must be declared as public to be accessed by outside code
    •    - must be a subclass of Applet (extends Applet)
  11. declaration of method paint()
    • public void paint(Graphics g){
    •    - paint( ) is defined by the AWT Component class (which is a superclass of Applet)
    •    - paint( ) is overridden by the applet
    •    - paint( ) is called each time the applet must redisplay its output
  12. paint( ) method has one parameter
    • - of type Graphics
    • - This parameter will contain the graphics context, which describes the graphics environment in which the applet is running.
    • - This context is used whenever output to the applet is required
  13. g.drawString("Java makes applet easy", 20, 20);
    • - call to drawString( ), which is a member of the Graphics class
    • - method outputs a string beginning at the specified X,Y location

    • java.awt
    •    java.awt.Graphics
    •       abstract void drawString(String str, int x, int y)
    •    - Draws the text given by the specified string, using this graphics context's current font and color
  14. 2 ways to run the applet:
    • 1) Inside Browser
    • 2) Using Appletviewer
    •       - development tool provided w the standard JDK
  15. Steps to run applet "Applet_Basics" using Appletviewer:
       - through stand-alone HTML file:
    1) Create HTML file named "SimpleApplet.html"

    •    <applet code="BG_515_410_Applet_Basics" width=200 height=60>
    •    </applet>

    • 2) Run SimpleApplet.html file
    •    C:\Users\The Kovalskiys\Documents\AAA NCC\Java\MyWorkspace\BG_515_410_Applet_Basics\bin>
    •    appletviewer SimpleApplet.html
  16. Steps to run applet "Applet_Basics" using Appletviewer:
       - through imbeded HTML file:
    1) Include a comment near the top of your applet’s source code file that contains the APPLET tag.

    • /*
    • <applet code="Applet_Basics" width=200 height=60>
    • </applet>
    • */

    2) Run "BG_515_410_Applet_Basics.java" file
Author
flashsmilenet
ID
330133
Card Set
AZK BG Java Applets
Description
AZK BG Java Applets
Updated