| overview lifeCycle |
Every applet is implemented by creating a subclass of the Applet class.
The following figure shows the inheritance hierarchy of the Applet class.
This hierarchy determines much of what an applet can do and how,
as you'll see on the next few pages.
Simple.
The Simple applet displays a descriptive string
whenever it encounters a major milestone in its life,
such as when the user first visits the page the applet's on.
The pages that follow
use the Simple applet and build upon it
to illustrate concepts that are common to many applets.
If you find yourself baffled by the Java source code,
you might want to go to
Learning the Java LanguagetutorialIcon (in the Writing Applets trail) to learn about the language.
/* * 1.0 code. */ import java.applet.Applet; import java.awt.Graphics; public class Simple extends Applet { StringBuffer buffer; public void init() { buffer = new StringBuffer(); addItem("initializing... ); } public void start() { addItem("starting... ); } public void stop() { addItem("stopping... ); } public void destroy() { addItem("preparing for unloading...); } void addItem(String newWord) { System.out.println(newWord); buffer.append(newWord); repaint(); } public void paint(Graphics g) { //Draw a Rectangle around the applet's display area. g.drawRect(0, 0, size(). - 1, size(). - 1); //Draw the current string inside the rectangle. g.drawString(buffer.toString(), 5, 15); } }
Simple applet to learn
about the milestones in every applet's life.
Applet class provides a framework for applet execution,
defining methods that the system calls
when milestones -- major events in an applet's life cycle -- occur.
Most applets override some or all of these methods
to respond appropriately to milestones.
Component class.
(AWT stands for Abstract Windowing Toolkit;
applets and applications use its classes
to produce user interfaces.)
Drawing refers to anything related to
representing an applet on-screen --
drawing images,
presenting user interface components such as buttons,
or using graphics primitives.
Event handling refers to detecting and processing
user input such as mouse clicks and key presses,
as well as more abstract events
such as saving files and iconifying windows.
Container class.
This means that they are designed to hold Components --
user interface objects
such as buttons, labels, pop-up lists, and scrollbars.
Like other Containers, applets use layout managers
to control the positioning of Components.
<APPLET HTML tag
to add an applet to an HTML page.
| overview lifeCycle |
Bhopal news
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100