0% found this document useful (0 votes)
5 views

java unit 4

The document discusses the implementation of adapter classes in Java for event handling, specifically focusing on mouse and keyboard events. It outlines the structure of abstract adapter classes that provide default implementations for event listener interfaces, along with examples of mouse and keyboard event handling. The document also touches on various components and layouts used in Java GUI development.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

java unit 4

The document discusses the implementation of adapter classes in Java for event handling, specifically focusing on mouse and keyboard events. It outlines the structure of abstract adapter classes that provide default implementations for event listener interfaces, along with examples of mouse and keyboard event handling. The document also touches on various components and layouts used in Java GUI development.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

?

dapter Class : 3t is a spectal do


that
java, auot.event ackag
ToMded n the
simplities event kandlingabsbact classes tha
eaptes clasges, Q30 all
Provide defautt tmplemantations, fo
Listenes întetace
Thethocs fn an evert
dist of Adapter lass n ava :

heytdoptey

indofdapte
4 Meuse Motionapter
y Conpeert tdapter
(ontaires Pdaptes
focy fdapte
)Mouse-fdaptes class TH is an abstnct dos
inplomarotalory fro the
tht pavdes detult
Nouse Listene and MouseMoton
mcthoods in tho
-Listents fntestaces.

mpost jua. auot. *; fzample eaterdy


public clas MoeDdapter Mouseftopte

ke Mouseftaptev Ezomiple (C)


Frame =mao Fome ("MQUSE Þdapte ");
dabel =meo dabel )3
l.setlrunds (20/0, 200, 20)3
f. add (l) ;
f. setSTze. (y00,4 4 0 0 ) ; g
f. setdayout (nulo); icr
f.setvitble (tuw);
l. addMeuse Aísteney (thfs)3
void mouse brteaed ( Mouse event e) f
puble
LsetTeat (Mouse Frted");

pubie state vofd matn(tingl]ags) i


dzanple0;
v) MUR hlaples
buu MOUse Poplet
Meuse Ehtered n

that
class
YKoyflagles: # s an abstact the mathod,
fnplomotatin for
Povides dehautt
tho kaylistren idetace.
Prcqnam:
impert jaua. auot. 3
*stgol,M
fava, awt. event,
imqort tample entends kayftaçhj
pule class keypdapter
hey daçteiExampe ("koy fetaptey ");
mes Frane
fiane f= mew dabel C);
Label =
L. setBounds (900,so, 200,20);eal)3
let
Teztoea aaca = new.
038a . set lounds (20,80 , 300,S0)
f. add (l);
foadd (aa);nlothbr .
f setiayct (ull);
f. set Visble (taue);
. oddkaylistens(ht);
publi void, kaypeleased (Kaybant e) i
tezt "aa, qelText ();
stm NoDIcls [ J=tet splüt (us");
:"4 Tds. lerngth + chaaces:"
I, set Tezt ("Wiods

statfc veid main (sting l3 g) i


pubtlte
toybdoglutanpbl );

oütput?

hai heb
Cutons Latton4
|Gutton |uton2
lrenuskaypd
tionple
(taue); settWsible fame.
selDetultclose frame
frame.
loo); (zoD; Size set 3
(new add foame.
);("Button TButton for(nt
iz53
TH) seliauuct i=I fame,
uyotlr
); (mew
tame JFrame
mainstring votd statie pubie
laullayoutFonpk class publíc
suofng.*; javaz, import
aut.
; * joua. iport Pgan:
to
thom toToppng
otneat layput: ow 7
ohen tompo aanqsthe
a in
dauot : H dvtdes the containes
) Borcer lert
20glons : ka Nortth, South, aat,
uto ive to specihie
cemponont 0e aolded
Lonter,
giens.

mpost jaa. auot. :


pubteclass
shpublíc static veid man (Sting angil){
Jiorne f z mew Thame (" Eosdedayotxanpe";
f. etiaycut (mew Rodedayut ');
f. add (new Jettn ( wNerth ), tondailauputzstait)
f add (new JRuten (useuth") Bolelauput.oti)
fraddl (reuo JButtorn ("east "), rndedaeot. atb);
-f.add Cneuo JGuttrn (woest), Koderdapt- ke;
t.add (nêuo TGctton (" certe), Cosdoyáguab. orte);
f setSize (s00, 30) ;
f. setEegultCbe Cperation (TPane., 6xiTL0N.cie}
f. set Viable (tre);i slok

Noth
Gost
Weyt |certer]
South
Sy Compenonty?iud
3Cpenart s an olject hauing gopr
oepresentation that an be displad
the SCeen.
frorm faua, aut. temponn
’Conponents
class
QAe derived

ommen Components i
) Butte
such as tom submiss+on (on
i99er acions ,
mavigoticn
This cdasCaeates alabelled btten
y e : Subnit cancl o îcon butbons

ay dabelsheriu
’pevtdes ceseiphve tet to eaplin the
pupose ef cenponert
’Label is the easiest contol to use
* Enter youy", "paiscard".

3 Textfields :
’ DUow wsess to Input t e t h s
’ H Ts a tert temenerdt thot alloos - to
cditng ot a single ine of teet
seach bexe
Cx: use1name fidds,
4yCheckboes :
select mulliples options fo
Enable ses to
a list
It is a that an
gaplial tonporent ott (talse) state
-

be ether n on (hue) ßr
5 kadioBcttons :
llo sers to select one option trom a
cafcesnt
Set et uitually exclusive
TetAreai
alloos
’ IIt 1s a text cemponent that
tor editng a mutiple lires et tert
’ t fs a pat ot aa (uT) and it Ts
wers to
Used in appiatera to allow tet
rtevat ith o Viey thomuti-lino

’ cece tont is used to show pop up

’ selecdted choíce Is duon on the top o


the morl
ekeckten

a collocton oh iterns în a
Vetical o kogizotal listi.
’ H allow wseys to selec ono o more lines
54 fs a geneic tontaines that ca
othes tonpeneni
fowa the types oh poncls ae párasily
debemined
to them,
by the laycut marages

7n aamqes tomponerts n a IO0, oapping


to the mext oo the is însuyticent spe
2 Conponers a centeud by deteult ht an
be alígned et rigkt or justihied.
2} Bordey Lauygt ponel :
Tt divides he panel irto tive taoíons
nosth, Soth eogt , west anal tenter
each region Can hld ono tempenond and
-ho centev eqion expands to till unued spee
I Gpid layout panel :
’ I anargs (empenats n a

munkey oos ard ceumns agg


tatialization
4 Bozlayat Panol
tomponerts the veslcaltly
’ Hattigns the
horiñzrntalya
DLTLaS
Dloas ter tlenibe spatng and ialtignmant
(enponants.
AT (lass Hferavcky

[chject|
Comçonent
7ChecKlon
choice
is t]
Contoine

wtndno Panel

Fone Díalog
* Event handing
proces of omanagfng
Ertohace) mterockicns , such as mouge Cia
sfincloo cctns oithin a
presses or
qraplical uses întertace. (GU).

3key tompenendy
tonpenerds ot vent
1 Event Sousce :
’The object that genuates, events
eL: Teuttor
Event cbject
?s
7 encapsulates ntormelien akout the everd.
er? cion Gent , OUse Event

3 Event istener:
’ -An intertece definíng mcthods to harde
specitie tyres o eventi
bclion Litener ,sMio tatener ,Keylitenl

oafe eeted ohen the -evendt occuLs


’ Tke
Kitten mîde the istener's methad
3t 1s
Event Deleqation Model
medel 1s the mechanisro
’ The event Delegation
used to handle event.

Xxx Event

(
XxxListeney
SouTCe <<întetacey
(of XxxEvent)
Xxx vent
istenes List
addXxxlsteney htenes(s)
(is :Xoelistena) levert- hardlel)t
reDVe Xxxlisteney
(lis:Xxlisterey)

Tegisters distene() hrch implemunta


appo0psiate Xx*distener intesace Via
the
SrC. addXistener(s) ibe
2 The soce s tggead by a user kbg
XxxEventlp)
3 The SoUSCe Cate a
istener (s) euert - hardles oth tho
4nvoke
XXxEvent objectu)etle
nteract wit
occuas ohen the wser such as dicktra
Cemponent using a the mOle
Preusing , sleastng and mostng
Example :
import java ,aut. *; w
impert joua, auwt. event.* j Frame npan
Mouseliterertiample extendu
Public class MeUse dstages
dabel l;
Mouse ListeneErample C)
add klouse kistenes (this);
l=nelodabel 03
l.setBaunds (20, SO, lDD) 20;o5X )
eadd ();
set Size (300 300) 3
h
sellayout (nut);
SetVisib le (tue);dnb oosy
public aoíd mDuse Clickod (MOUse Sient e) f
L, setText (MoUse clickad");Xh.N
public voie mouse Entetd (Mouse Eient e)
l. sel Text ("Mouse Enlesed");
public votd meuse Eited (Meuse Eent e) f
l. setText (M Mouse Xited");

pubic l.vDjd mouse Pressed (MaDuse Event e)


set Text (u taBuse Pressed");
publt void moue Rolcaed /Moué 6ert e){
. setText (" Mouse Released );

pulkic state veid main (ting(3 ag) t


eo
Meusedistenesfxample ;

Mouse tnteod.
*hayfnnd Eventi
events occuu vohon ho user nteot
’heykonnd
woith the Such as presirg

Ezampe :
impost JoNO. Cuot.*;
impost jova . aut. event.*;
public class haylistenenuarple erderds frame

label l;
Tet rea aa

keystenes eample ( )
l= me labell);
aa0a = me Tett Ayea C)3
1.setBounds (20, so, l00, 20);
aaa. Set Bound (20,sO, 80, 30o)
ania.add eydistenen (tis);
add () ;
add(eca);
setsuo( 4D,40D);
setlauout (nu);
se<Vistble (tue)s

patic void kouyfe sod (key Gent");e) i


. sekTet ("Key Presed
ubltc vot Kauyleleased (Kuyewrd e) i
1.SetTezt (" koy Peleand ");
3
publie statie veid main ( stárg CI aags) 1

|-|Dx
Koy Peleased

You might also like