Events and AppletsEvent Tutor AppletThe following applet is designed to give you some feel for just what event driven programming is like and what the various events you're likely to encounter are. Whenever an event occurs, the applet responds by printing the name of the event at the command line.import java.applet.Applet; import java.awt.*; public class EventTutor extends Applet { public void init() { System.out.println("init event); } public void paint(Graphics g) { System.out.println("paint event); } public void start() { System.out.println("start event); } public void destroy() { System.out.println("destroy event); } public void update(Graphics g) { System.out.println("update event); } public boolean mouseUp(Event e, int x, int y) { System.out.println("mouseUp event); return false; } public boolean mouseDown(Event e, int x, int y) { System.out.println("mouseDown event); return false; } public boolean mouseDrag(Event e, int x, int y) { System.out.println("mouseDrag event); return false; } public boolean mouseMove(Event e, int x, int y) { System.out.println("mouseMove event); return false; } public boolean mouseEnter(Event e, int x, int y) { System.out.println("mouseEnter event); return false; } public boolean mouseExit(Event e, int x, int y) { System.out.println("mouseExit event); return false; } public void getFocus() { System.out.println("getFocus event); } public void gotFocus() { System.out.println("gotFocus event); } public void lostFocus() { System.out.println("lostFocus event); } public boolean keyDown(Event e, int x) { System.out.println("keyDown event); return true; } } Once you've compiled and loaded this applet play with it. Click the mouse in the applet window. Doubleclick the mouse. Click and drag. Type some text. Resize the browser window. Cover it and then uncover it. Keep your eye on the standard output (Java console in Netscape) while doing this. Here are some questions to answer:
Finally there are a whole lot of new event methods. We'll cover them in detail in the next section. For now see under what circumstances you can make each one happen.
|
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