-
applets are -
are small programs that are designed for transmission over the Internet and run within a browser
-
applets provide -
secure way to dynamically download and execute programs over the Web
-
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
-
AWT
- - Abstract Window Toolkit
- - is original GUI toolkit
-
Swing
- - is built on top of the AWT
- - is lightweight alternative GUI
-
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);
- }
- }
-
import java.awt.*;
- - AWT-based applets
- - awt - Abstract Window Toolkit classes
- - AWT contains support for a limited window-based, graphical user interface
-
import java.applet.*;
- - AWT-based applets
- - contains the class Applet
- - Every AWT-based applet that must be a subclass of Applet (extends Applet).
-
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
-
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)
-
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
-
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
-
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
-
2 ways to run the applet:
- 1) Inside Browser
- 2) Using Appletviewer
- - development tool provided w the standard JDK
-
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
-
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
|
|