You are on page 1of 4

r Q• 17 ,-.

,vl'n t I landlln~
.~ ~ -------

ts (here the same applet acts as a event


,pplel has to regi~ ter itself as a listener to vari ous even
;i;t a~ u,r/1 nf: rr,e 11 t lr.i; fm cr) . Hence insid e init()
method applet regiRters itself as a listener by
.n ring statements
/,wOII • •
addM ouseL1stener( this);
sddMouseM otionListene r( this );
The getXO and get YO methods retu rn
,IJld then simple methods of mouse even ts are defined.
each of these methods an object of Mouse Event
is
uie rorrent x and y positional values. To
~ which is shown by a vari able 'm'.

Review Question
ple program.
1. Discuss mouse listener and mouse motion listener. Give an exam
AU: Dcc.~19, Marks 13

[i] AWT Event Hierarchy AU: JT .: .Dec.-12, 13, Marks· 16

In Java event handling is done using object orien


ted methodology, EventObject class is
are descendant of this class . The AWTEvent is a
defined in java.util package and all the events
class derived from EventObject class.
The AWT Event Hierarch y is shown by following
Fig. 9.6.1
Base class
Event object In hierarchy

AWTevent

· Component Item event


Action ·Adjustment event
event event

Window
Focus event Paint event event
Input event

Mouse event
Key event

MouseWheel
event

Fig. 9.6.1 AWT Event Hierarchy

~ -- -= = = :~ ~ ® ~ :: :: := ~ -- -
TECHNICAL PUBLICATIONS - An up thrust for knowledge
''!!:~~ ~~~~ ~!!!:._
~~~l ()rienttd 1::"r•"'"'''~ .- - -- -- - -'-''_._ ____ ____ ____n. :.:,~~ra:.:.~i thth S..c. ,'n·o
- ~ 1

• 10.1 Introduction to Swing


RIB•i4◄ z
• Swing is another approac h of graphical p rogram ming in Java. ~
• Swing creates highly interactive GUI applicat ions.
• It is the most tlexible and robust approac h.

I
( 10.1.1 Difference between AWT and Swing

}/~ ~}~\~df eel ofAWT liepends upon ·


"'.1)1;~~\: _,, ,: -' . . .

Following are some limitations of AWT -


1. AWT supports limited number·of GUI
. components.
2. The components defined by th AWT . . . .
3. The behavior of AWT e are heavy · h
we1g t components. eS·
- components varie h cha!lg
4 Th AWT s w en the containe r operating system
. e components are develo ed b . .
5. The AWT component i·s co p Y USmg the platform specific code.
nverted by th .
. . . e native code of the operatin g system-
The slider component

~ Swing Class Component Hierarchy


ln Order to display any )Comp onent on the G UJ, it .is necessa ry
to add this compo nent tu th
<antainer
. first If d ot add these compo nen ts to container then 1t will not be d 1 _e
'" t .
he GUJ Th
you on
.
_..i

compo nent hierarc hy 1s as shown by fo llowino F, o 10 1 1 u.p °''""


.
· e swing c1ass · o o· .
I' . u
, •u1:,rarnrning w·th

I ~
~

1:
-g_ ..! ....
CD
C C1J .
C
Cl>
8. CCI
::,
I C:
Q)

l:a- g j
C
0
~
~
-,
0 0)
q 0 0 C 32
a,
l 'ien ~
C
i .....C
~
.!! . C'O

....~
C'O
~C'O
..... ~ca
..... e
.....
ca
(1)
C
8.
.s
i
.s
i -i -
0 0
en 8
x
E
(1:1

!
0
.!
0

l
0
~
.2
.!
~
-,
I
t:;
X
0
al
.8
E
0
(._)
-,

Fig, 10.1.1 Swing class component hierarchy c1ass•'


There are two import
. ant features of swmg. components • Firstly, all the companeo!TIPon•
nt ,1
begin with the letter) and secondly all these GUJ compo nents are descen an t of JC
, . d
class. Let us now learn how to place these compo nents on the GUI.
Review Questions
1. List and briefly discuss ~he swing components in Java.
2. State the difference between A WT and swing.

TECHNICAL PUBLICATIONS®• An uo thr11.,, "M ,___ .,_,_ J _ _

You might also like