Java Last Unit 3
Java Last Unit 3
4. Add (Compone nt c, int zone) method is used to add any componen t to the container.
5. Zone argument may be one of the following-
(i) BorderLay out.NORTH (ii) BorderLay out.SOUTH
(iii) BorderLay out.EAST (iv) BorderLay out.WEST
(v) BorderLay out.CENTE R
6. Border layout can be created by using one of the following constructor .
Construct ors of Border Layout Class :
S.No.
1.
Constructors
BorderLayo ut()
S.No.
1.
Description s
It creates a new border Layout
--
2. BorderLayo ut(int hgap, intVgap) 2. It creates a new border layout with a horizonti
gap ofhgap and vertical gap of Vgap.
Methods of BorderLay outClass : -
S.No. Methods S.No. Description s
1. setHgap(int hgap) 1. It sets or changes the current horizontal gap to hgap.
2. getHgap() 2. It returns the current horizontal gap.
3. setVgap(int Vgap) 3. It sets or changs the current vertical gap to Vgap
4. getVgap() 4. It returns the current vertical Gap.
PROGRA M 13.14: Program to show the arrangement of componen ts using Border Layout Manager.
Step I : Code for border.java
bon!er,java - Notepad
F,!e Edn Format Vlf:W Help
import java.awt.*; r
import Java.applet .#;
public class border extends Applet
{
public void init()
{
BorderLayou t b=new BorderLayo ut();
this.setlay out(b);
Button buttonl=new Button !"Buttoi:il "l;
l
E
Button button2=new Button "Button2" ;
Button button3=new Button "Button3" ;
Button button4=new Button "Button4" ;
Button buttonS=new Button "Buttons" ·
this.add!but tonl,Border layout.CEN TER;;
th,s.add button2,Bord erLayout.NO RTH)·
this.add button3,Bord erLayout.SO UTH):
this.add button4,Bor derLayout.E AST)·'
this.add buttonS,Bor derLayout.W EST);
}
}
Fi9. :1.3.:1.8(t:t)
Step 2 : Code for border.htm l
border.html · Notepect
File Edit Format View
<HTML>
<BODY>
<APPLET code="border"
w;dth=200
he;ght-100 >
</APPLET>
</BtJOY>
</HlML>
301
AW T
ChaPter I3 - GUI Prog ram min g with
Step 4 : Output
. com pile and Run the pro gra m
steP 3 •
--
.oom -
r ~
~
IIIIDn5
llllllln2
IMIDn1 .....
IMIDn3
1AN1111111111e1.
Fig. J.3.J.B(d)
F 9 :L3 :LS( c)
out.
also specified its zon e in the Bor der Lay
In this program,,~ c add ed fh c hut ton and
PR.OGRAM 13.15: Program to show the arrangement of components in Card Layout Mana
Step l : Code for card.java ge.,,
//Event Handlin~
RUblic void act1onPerformed(ActionEvent e)
{
if(e.getsource()=buttonl)
{
c.next(pl);
c.show(pl,"Card 2");
}
else if(e.getSource()=button2)
{
c.previous~pl);
c.show(pl,'Card 1");
<HTML>
<BODY>
<APPLET code-"card"
width=150 E
height=150>
</APPLET>
</BODY>
</HTML>
Fi9. :1.3.20(b)
.
card.html
.
ps;
... ◄ I ,. ·~
,,,,. ;::....- !
~__,
-
--,,._ '4,
' ,.,. T
-. - • I
,..-
E..'\.1llllpk :
1..~'l:1 .dl~hc, ,n.,t[dl lltS. g11d:< 2;
Cl1dB 1q~0n strd1n ls . gridy - 2;
~- f_rid";dth, gridhe ight : The grid width and grid height constr
aint~ are used to control the size of
mron~ nt A con1ponent ma)' use one or more cells. So we can create
,\ -.'.\.1
. . different layout by specify•
. . . b
numb1.:'r$ ot cells in a row for grid width or colum n for gndhe 1ght as given e1ow .· ing the
Exam ple:
GridB agCon strain ts . gridw idth = 3;
GridB agCon strain ts .gridh eight = 4;
3. Fill: Fill is used to determine wheth er a compo nent fill the availab
le space either horizontally, Verticall
or both. Fill is used when the compo nent's display area is larger than
the compo nent size. y
Const ants used :
1. Grid.Bag Constr aints. NONE (By default)
2. GridB ag Constr aints. HORIZONTAL
3. Grid.Bag Constr aints. VERTICAL
4. Grid.Bag Constr aints. BOTH
GridB agCon strain ts.HO RIZO NTAL changes the width of compo
nent so that it fills the components
displa y area horizontally. But it does not changes it height.
GridB agCon strain ts.VER TICA L : Changes the height of compo
nent so that it fills the component's
displa y area vertical. But It does not change its width.
GridB agCon strain ts BOTH : changes the width and height of the
compo nent so that the component's
displa y area fills entirely.
4. ancho r : The anchor is used to contro l the positio n of cell. It is
used when the size of component is
smalle r that its display area ancho r is an integer value that can use
the following consta nts :
(i) GridB agCon straint s.CEN TER (Bydefault)(ii) GridB agCon straint
s.NOR TH
(iii) GridB agCon straint s.NOR THEA ST (iv) GridB agCon straint s.EAS T
(v) GridB agCon straint s.SOU THEA ST (vi) GridB agCon straint s.SOU TH
(vii) GridB agCon straint s.SOU THWE ST (viii) GridB agCon straint s.WES T
(ix) GridB agCon straint s.NOR THWE ST
5. ipadx, ipady : ipadx and ipady is used to specify the compo nent's
intern al paddi ng within the layout.
It define s how much to add to the minim um size of the compo nent.
Atleast, the ,-vidth of the compo nent will be
minim um width of the compo nent+ (ipadx*2) pixels
Atleast, the height of the compo nent will be
minim um height of the comp onent + (ipady*2) pixels.
6 - insets : insets is used to specify the extern
al paddi ng i.e., the minim um space betwe en the component
and the edges of the compo nent's display area. The inset setting takes
a java.a wt.ins ets object as its value. B)
default, the inset space is left blank so that it can be used to define
a borde r or title.
7 · weightx, weighty : weightx, weight
y is used to stretch rows and colum ns. It is not used for individual cells-
lt all th e colum ns have value O and only one has value 1.0, then the
the maxim um available space. one that has value 1 will st retch 10
import java.awt.~; •·
import 3ava.applet. ,
P.ublic class gridbag extends Applet
{ ~ublic void init()
{ Label ll=new Label("Himanshu Garg");
sutton bl==new Button("OK");
Gri dsageons trai nts gbc=new Gri dsageons traints () ·
GridBagLayout gbl=new GridBagLayout(); '
Frame f=new Frame("New Frame");
f.setsize(200,100);
f.setLayout(gbl); r
gbc.gridx=O;
gbc. gridy=O;
gbc.weightx=150;
gbc.fill=GridBagConstraints.HORIZONTAL;
f.add(ll,gbc);
gbc.fill:GridBagConstraints.V~RTICAL;
gbc.gridheight=3;
u
gbc. we~ ghtx=2 5; .
gbc. gn dx-+-+;
f.add(bl,gbc);
f.setvisible(true);
}
}
Fig. j.3.:Z.O(a)
<HTI4L>
<APPLET code= "gr,'db a9
<BODY> II
=
width=250
height:250>
</APPLET>
</BODY>
</HTML>
Fig. j.3.:Z.O(b)
~ C:\WI nows
d \system32\command com
= @J ~
.
D:\PROGRAMS>javac
gridbag. java
-
D:\PROGRAMS>appletviewer gridbag.html
...
►
l
◄ lit
Fig. 3-3.:w(c)
A Functional Approach to JAVA OOP Foundations
306
Step 4 : Output
f:! __ _ _ _ O X
Al>f)let
11:} ~Fra- I 0 ! El 1l
H1mansnu Garg
At)plet started
Fi9. :n .20( d)
In the above program, we added one label with text "Himanshu Garg'' and one button with title "OK"
to the frame having title "New frame': We used GridBag Constrainsts to customize these components and
arranged them using GridBagLayout Manager.
i11MIM:i;tlil
----------------------------------------------------------------- -------·---
..- Java provides a class library known as Abstract Window Toolkit (AWT). It i-. platform independent and create applets as well
as stand alone applications that run in GUI environment.
..- AWT consists of 12 packages. These packages contain a number of AWT classes that are used in GUI programming. The
core AWT classed are contained in the java.awt package. The most commonly used packages are-
1. java.awt package
2. java.awt.event package
.,,, Components and container are the main AWT classes. Component is an abstract class that encapsulates all the attributes of a
visual component. It is at the top of AWT hierarchy. It supports a variety of graphical elements such as Labels, Buttons, Text
field, TextArea, CheckBox etc.
Container is used to hold components. The container class is a subclass of component.
....
~-
Fr"1M Is a 811.ia ll'indow for Applets and stand alone applications which bas a tide bar, an optional menu bar and C()l2tent
wcamgroupvariOUS ~
AWT components-
. Chanter 16
EVENT CLASSES
J,wa provides us v,\rious L'Vcnt classes lo represent l he events. 'Ihese event classes are at the core ofJav ,
c..'\'c..'nt handling tnl.'chauism. 'lhus, a discussion of event handling must begin with the event classes, 1h:s
pnwic..k ,1 consisknt and casy to usc means of encapsulaling events. Java defines several types of events b!t
we will dis1.·uss thosl.' event classes in this chapter which arc more frequently used.
. . . .. .. . Event
16.1.1 . .. .
Object Class
. .... ....... ...
Evc-nt ob_ject dass is the root class of the Java event class hierarchy from which all event state objects
shall be derived. It is the superclass for all events. 'fois class is defined in java. util package.
Class declaration :
TI1e dedarntion forjavn.util. Event object class is as follows:
public class Event Object
extends object
impleme n ts serializable
Field:
TI1e field for Jaw1.11til. Event object class are as follows:
p rote ct e d object source
S.No. M.tho4
1 getsource( ) Dam tion General for"!.
This method returns the source of the event. It object getsource( )
represents the object on which the event initially
occurred.
2 toString( )
Thia method return, the string equivalent of this stringtostring( )
_ Event Cla~,e,; 335
chapter J6
£VENT CLASSES
,, 14'/'ff · · 1 ss is defined within the 1ava.awt package.
A6,~
> · 4e AW' '
J"
paC
'(f.Vel'll C a
. v,i aw1.c
J<,tge J" ·
b sevcra
vent defines vanous types of events that
I user mtcrface elements It 1s a subclass of I
·M•i•,
- •_;,a-x•:__
1ne nerated Y cla 5 of all AW r ba ed events u~ed by the
.,ege t but super ,,,_,,-,.C,110.,,,.,dauofoll..,.,.,._
_. ob•ec nt Mode I
f,,ent i
cga11° 0 f,H blc -;howlng the n.m1c of mo t frequently
A.WT,,,_,,., a_,,,.,
dau ol all A.wr _.,.
D'l , llo" ,ng I .1 1 fttot ere handled by ,,_ Delegation Event
'f11c •0 I Jm ",de a brief d cnption as oc1ated
1 J,1 <,C<; JJH1• O Model, - .,;a dudy lofw.
d t"ctl
1
h main J \cnl da In ;ma awt ever,t are a,;
u,t aJlll c
1he1r o
,,11h
folJOI\~
,,,,,,<111 Ducrlpllon
It I o< t <'.'le of II AWT evcnl'>. This class and all 11s subclasses
u th ori m I 1ava
It wh n ,1 butt 1st item is double clicked or a menu
Adi< nf Hill
2 d
ntl , nt It I
; Ad
nt I , nt It I wh n a c.ompo med res1ud, hidden or becomes v1s1ble.
.. (o I
lh I c.l rcprc nt cm stock of a window.
111 omponcnt I
5 rcprc nt t state of a window.
hx.U l:HOI 11 g ncr tc-d when a component g.iins or lo keyboard focus.
6
11 t r , t C\ nl d for all wmponc-nt IC'\el mput c-,rent classes.
In uth , t
lteml ,e t It I
-------------i
ncr tcd '1ihcn ~he k menu 1tc-m (check box or list Item etc.) 1s selected or
8
cl Ice too or d1 kcd
.~~~----
111 gcnc:r ted ~hen am input is rcccwed lrom the keyboard.
------'-----------!
10 Mou hcnt It I gcncr ted \\hen the mou~ ts clicked released moved or dragged and also
ncratc:d ,,hen the mouse actions occurred (enters or exits) ma componc-nt.
11 It t c1 crated \\ hen the mouse wheel 1s moved. (This Event class 15 added by
J \ 2 \er wn l 4)
12 It I
---
generated \\ hen the \"alue of text field or text area 1s entered or changed.
13 It ts gener.:atcd when a w,ndo"' 1s opened. actJ, ated, icomfied, closed, deactivated.
detcamfied or quu Inc obJect of this class represents the change in state of a
\\tndO\\
(I) AWTEvent class: 1he A\\ Tfaent classes represent the event. It is the root class from which all
C\'n!t statr obJ«ts shall bedenved.
Wr have studied this detailed m the begmnmg of this topic 1.e. Event classes.
~l) The ActionEvent dus: The Act1onfaent 1s generated when a button is pressed, a list item is double
or a menu lS selected.
1he ActionEvent class defines these 5 integer constants:
Daaiplion
1bese 4 integer constants are used to identify any
modifies associated with an action evenL
Here, -
src is a reference to the object that generate d this event.
type is used to represent the type of the event.
cmd is its comman d string.
modifiers argumen t indicates which modifier keys.
(ALT, CTRL, META and/or SHIFT) were pressed when the event was gen
erated.
when paramete r specifies when the event occurred .
d to decrease
!he blutton at the end of the scroll bar was clicke
its va ue.
· d'1cates that a
NGED th at m
·o·on there is an integer constant, ADJUSTMENT- VALUE- CHA
In addl
has occurred.
change . one AdJ·ustmentE vent Constructor:
J{ere 1s • . . .
int data)
AdjustrnentEvent (AdJustable src, i_nt id, mt type,
this event.
Here, src is a reference to the obJect that generated
id equals ADJUSTMENT_ VALUE_CHANGED.
type is used to specify the type of event.
data represents its associated data.
Adjustment Event class has these methods :
Description General form
Method
S.No. . Adjustable getAdjustable( )
It returns the object that generated the event
getAdjustable( )
I I. int getAdjustment Type( )
It obtained the type of the adjustment.
2. getAdjustmentType( )
int getValue( )
L It obtained the amount of the adjustment.
I 3. getValued( )
A,-.:pw_,,,--.,-,__.
For__,,.,~,,,., ..
,,.-;,.,o,crollbar;._..,_
utEvent Class
(7 )'lbe InPt class JnputEvent 1s a sub class of ComponentEvent and is the superclass for component
'Jhe abstrac
Its subclasses are :
,..,ents.
jJ1pUt .,.
J. J(eyfvent
2. MouseEvent
lass defines a number of integer constants that represent modifiers. Originally, the
C
ven t defined
1nputEclass the followmg 8 values to represent the modifiers:
Jnput£vent
1.ALT_MASK
2_ALT_GRAPH_MASK
3. 5UifON 1 MASK
4. alJTI'ON2 MASK
s. BUTI'ON3 MASK
6. CJ'RL_MASK
Do You
Know?
8 modifier values :
340 A Punclion al Approac h l )
o AVA OQp F
lnput Event class has the following method s : Oundat·
IOI)\
-----
1. SELECT ED The user selected an item.
2. DESEL ECTED
S.No.
1. KEY _PRESS ED
Constants
constants
Description
These two event are generat ed when any key is
~
:
· presse 0
--
2. KEY RELEASED released . I
3. KEY TYPED This event occurs only when a characte r is generated,
VK_EN TER
VK_ES CAPE
VK_CA NCEL
VK_UP
VK_D OWN
VK LEFI'
6 _ Event Classes 341
Chapter 1
yI(_IHGHT
yJ(_PAGE_DOWN
yJ(_PAGE_ UP
yJ(_SJ-IIFT The VK constants specify virtual key cods and
these ore independent of any modifiers such
vr<_ALT as ctr/, shift or alt.
yJ(_CONTROL
t is a subclass of InputEvent.
I(eyEve n
...,any constructor s two of then are :
It has,..
~- Constructor Description
,-- .
KeyEvent (Component src, mt type, long It generate the key event with the specified type.
J. when, int modifiers, int code) The system time at which the key was pressed is passed
in when.
v - KeyEvent (Component src, int type, long Code is the virtual code such as VK_ UP. ch contains the
2. character equivalent.
when, int modifiers, int code, char ch.
L.--
The KeyEvent class defines various methods. The most commonly used Methods are :
--
~
S.No.
l.
Method
getkeychar( )
Description
It returns the character that was entered.
General form
char getkeychar( )
~
5. MOUSE MOVED The mouse moved.
~
6. MOUSE DRAGGED The user dragged the mouse.
~ n
- 8. MOUSE EXISTED The mouse exited from a component.
Mo11se£ve t.rs a subclass of InputEvent . Here is one of its constructor s.
~ ; e n t (Componen t src, int type, long when, int modifiers, int x, int y, int clicks, boolean
Jlere, S1i •
c 15 a reference to the componen t that generated the event.
type specifies the type of the event.
34 2
A Fun ctio nal App roac h to JAVA Oop
F
whe n specifies the syst em tim e at whi ch oun.dati0
the mo use eve nt occ urre d. ns
modifiers arg um ent indi cate s whi ch mod
ifie rs wer e pre ssed whe n a m
x, y are the coo rdin ates of the mou se. ouse eve
nt Occ11.....
clicks specifies the click cou nt. ""(t~
I ~;.
) ,·o. , Whee!Rotation() It returns the number of rotational units. int getWheel Rotation( )
1 ' get The positive value indicates the wheel moved
counter clockwise and negative value indicates the
wheel moved clockwise.
Constants Description
DOW_OPENED The window was opened.
DOW_ACTNATED The window was activated.
DOW_ICONIFIED The window was iconified.
DOW_CLOSED The window has been closed.
OW_CLOSING The user requested that the window be closed.
W_DEACTIVATED The window was deactivated.
W DEICONIFIED The window was deiconified.
_GAINED FOCUS The window gained input focus.
_LOST FOCUS The window lost input focus.
STATE_CHANGED The state of the window changed
s•• ,\ I 1111, li1111,il 1\pprnt1 r h to Ji\V
,\ Ocw I
1
\\ rndtm I , -rn\ 1:-. i\ ,;u\h lus~ 1,.l( l \ 111lplH 1cnl Event. 1t d('f111c s I he following
' hr1d
ti 1
c;on<:t ruct
:S.1'\b hrs
Cm,st rfldor ·
l \\ m,t,m h , nt l\\findl ,,,. 1'1<, int typt')
\\ md1..1,, r, 1..'nt l \\"mdo w src, int type, windo w other)
\\ mdowE vcnt (\Vind ow src, int types, int from state, int to state)
-0. \\'indo wEven t (\Vind ow src, int types, windo w other, int transla
te, int to state)
Here. src is a refere nce to the object that genera ted this event.
type specif ies the type of the event.
other specifies the oppos ite windo w when a focus event occurs .
froms tate specifies the prior state of the windo w.
tostate specif es the new state that the windo w will have when a Windo
w t
sate chang
' ' ' ~ -...• •
e occur1.
I - --"'W""'l•
Origina lly, Java has the first construc tor and method . Other 3 construc
tors and methods
are added by Java2 version 1.4.
Comp oncnt l1idd <'n() Jt defines 4 meth ods for receiving the
L-- ~pon entL istnc r comp onent event s.
J, Comp oncn tShow n()
Comp oncn t.Mow d()
Comp onent Rcsiz ed( )
- --- --+ --~ -
It define,; 2 meth ods to recog nize when a
~
Comp oncnt Addc d( )
~ -ContainerListcncr comp onent is added to or remo ved from a
4. Comp ont'n tRern ovcd( )
conta iner.
I
focuslistener
- focu~Gairwc.f ( ) It defines 2 meth ods to recog nize when a
I s. comp onent gains or loses keybo ard focus .
focu.-.1..ost( ) - --- ~-- --- ---
--- --- --1 --- ., -one -- · -
..... --- --1 --- ---
nged( ) It define_ meth od to recog nize when the
iteSta lcCha
6. /I Item rstener
L"
...tatc of an item chang es.
keyPr essed ( ) It defines 3 meth ods for receiv ing the key
KeyListener
I
7,
keyReJeased{ ) event s.
i keyT yped ()
mous ePres sed() It defin es 5 meth ods for receiv ing the mous e
8. MouseListener
mous eClic ked( ) events.
I mous eEnte red()
mous eExit ed()
mous eReJe ased( )
9 mous eDra gged () It defin es 2 meth ods for receiv ing the
· MouseMotionListener
_ _ _---l
-rn-o_u_s_eM_o_t1_·0_n_E_v_e_n_ts_ _ _ _ _ _
--i--------_J__m:_o_u_s:._e_M_o_v:_e_d...:(:..::)~----~
mous eWhe elMo ved() It de.fines one meth od for receiv ing the mous e
IO. M<>useWbeeJListener
whee l events.
r--- _ _
1
-+1-I-td_e_fi_n_e_s_o_n_e_m_e-th_o_d-to_r_e_c_og_n_i_ze_w_h_e_n_a_-1
tCh_an_g_e_d_(_)_ _ _ _
__
It 11-:-entist-:-._en_e_r_ _ _ _+-te_x
'I he Al t1<m Liste ner Inter face defin e the actio nPer
form ed() meth od whic h called wh
(hXll rS
'. en an act·
Gene ral form of this meth od: Jc,n
t-r
void actio nPer form ed(A ction Even t ac)
2. The Adju stme ntLi stene r Interface:
The Adju stme ntLis lener Inter face defin es the adju
stme nt valu eCha nged () meth od h·
an adju stme nt even t occu rs. W tch I
ca led "-'hen
Gene ral form of this meth od:
\1
void adju stme ntVa lueC hang ed ,,.
(Adj ustm entE vent ac)
3. The Com pone ntLi sten er Interface:
The Com pone ntLi stene r Inter face defin e four meth The compo nentM oved and
ods as compon
given in prev ious table whic h are calle d when metho d are provid ed for n f'f/ .enfResiied()
a com pone nt is only.
0 1
co lion purpo
hidd en, show n, mov ed or resiz ed. les
., ,1jstencr Interface:- . .
,., 'lhC Kt} , •
cr intc
-
rfJc e defines thre e met hod s for rece1vmg the key events :
,. •. ,
. t,.:t'rl.t!i 1t 11 hod
.
ts called when a key is pressed·,
·
lhl ·) '( ll' t, k,,,f Jresscd () met
1 released and
(
1
Rt•le·ised( ) method is called when a key is
·· ) kl'V
n a character has been entered.
•
('.'. k, '·T)rped( ) method is called whe
(ill) t:)
. three events are
f1r
1
l•xmnple :
release an}' cha ract er key 1.e. A or I or$ etc., then all of these
(') If we press and
d and released.
crenerated in sequence key pressed, type
1
FS etc. then only
s and rele ase any fun ctio n or related key i.e. Page Up or Home or
·') ~- we pres s of these
are gen erat ed in seq uen ce - key pressed and released. General form
(ll two key !!Wills
methods arc:
Met/rod General Form
S.No. ---
- - .
useListener Interface:
8, Jhe Mo
hods for receiving the mouse events:
The .i\IouseListener interface defines 5 met released at the
seC1ick ed( ) met hod is called when the mouse button is pressed and
(i) The mou
same point. ent.
ed when the mouse enters a compon
(ii) The mouseEntered( ) met hod is call
(ill) The mouseExited( ) met hod is
called ,vhen it leaves.
n the mo use button is
eleased( ) methods are called whe
(iv) The mousePressed( ) and mouseR
p~ d and released, respectively.
General forms of these methods are :
Method General Form
£No.
1. mouseClicked( ) void mouseClicked (MouseEvent me)
9
•Dae MouseMotionListener Interfac
e:
events.
ionListener interface defines two methods for receiving the mouse motion
1he MOUSeMot
--~,;.~. Description
.... ~ ' ~ .':.:_ -
- General fon n
is
It is called multiple times as the mouse
IIIOasel>ragged( ) void mouseDragged (MouseEvent me)
dragged.
'-. . is
It is called multiple times as the mouse
~() void mouseMoved (Mouse Event me) moved.
.............
It 'Ille Mo.se . .
\e ~ Wh ~is ten er Interface:nes one method for rece1vmg the mouse wheel event.
Wheelustener interface defi
348 A Fun ctio nal App roac h to JAVA OO
P Fo d .
un ations
Thi s me tho d is call ed wh en the mo
use whe el is mo ved .
- - - --------,---
---------: G-:-e_n_e_r_a-;lF=-o-rm
_ _ _ __
S.No. Met hod
1. mouseWheelMoved() void mouseWheelMoved (MouseWh
eel Event mwe)
11. The Tex tLi sten er Interface:
The Tex tLis tene r inte rfac e def ines
one me tho d to rec ogn ize wh en a
Tex tCh ang ed( ) is call ed wh en a cha tex t val ue changes.
nge occ urs in a tex t are a or tex t fiel
d.
S.No. Met hod Gen era l Form
1. textchanged( )
rface:
----
two me tho ds for rece ivin g win dow
(i) The win dow Gai ned Foc us( ) me foc us eve nts.
tho d is call ed wh en a win dow obt
(ii) The win dow Los tFo cus () me ain s inp ut focus.
tho d is call ed wh en a win dow loss
es inp ut focus.
S.No. Met hod
Gen era l Form -
1. windowGainedFocus( ) void windowGainedFocus (Window
Event we)
2. windowLostFocus( ) void windowLostFocus (WindowEvent
we)
13. The win dow Lis ten er Interfac
e:
The win dow Lis ten er inte rfac es def
ines sev en me tho ds for rec eiv ing
(i) The win dow Op ene d( ) or win win dow events:
dow Clo sed ( ) me tho ds
are call ed, respectively, wh en a win
dow is ope ned or
clos ed.
(ii) The win dow Clo sing ( )
me tho d is call ed wh en a win -
dow is bei ng clos ed.
Mou se Whe e/Lis tene r interlace and
(iii) The win dow Act iva ted (
) and win dow Dea ctiv ate( ) Win dow focu s Listener interface was
me tho ds are call ed wh en a win dow added by
is acti vat ed or Java 2, version 1.4.
dea ctiv ated , respectively.
(iv) The win dow lco nifi ed
and win dow Dei con ifie d me tho ds
or deic oni fied , respectively. are call ed wh en a win dow is iconified
, •• w
Object
AdjuatmentLJstner The.Ad
AdJ
ComponentLlatener
CcJatltaerLlltener
350
.,...
A Fum.tlonal Approach to JAVA OOP Found t ........
~
pLogtam p = new program (f);
if (e.getsource( ) ==b)
count++;
system.out.println ("Button is Pressed");
t.setText("Himanshu Garg"+ Count);