Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Java Lab Programs

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 64

DEPARTMENT OF COMPUTER APPLICATIONS

PROGRAMMING IN JAVA LAB


PRACTICAL NOTE BOOK
Submitted
by
Reg.N!
For the Degree of
BAC"ELOR OF COMPUTER APPLICATIONS
#
UNIVERSIT$ OF MADRAS
DEPARTMENT OF COMPUTER APPLICATIONS
%&'&(%&''
DEPARTMENT OF COMPUTER APPLICATIONS
BONAFIDE CERTIFICATE
This is to certify that the report entitled PROGRAMMING IN JAVA
PRACTICAL NOTE BOO !ein" s#!$itted to the %ni&ersity of Madras'
Chennai !y (Re")No* + for the partial
f#lfill$ent for the a,ard of the -e"ree of Bachelor of Co$p#ter .cience is a
!onafide record ,or/ carried o#t !y her #nder $y "#idance and s#per&ision)
-ate* .#!0ect In1char"e
.#!$itted for the practical e2a$ination held on at .hri
.han/arlal .#ndar!ai .has#n Jain Colle"e for 3o$en' T)Na"ar' Chennai1
455567)
E2a$iner1I E2a$iner1II
S.NO DATE NAME OF T"E PROGRAM
PAGE
NO
SIGNATURE
' SUBSTRING REMOVAL FROM A STRING
%
AREA AND T"E PERIMETER OF A
TRIANGLE
)
RANDOM NUMBER GENERATION USING
RANDOM CLASS
* USAGE OF CALENDAR CLASS
+
IMAGE MANIPULATION FOR POINT
CLASS
, STRING MANIPULATION
-
E(MAIL ADDRESS SORTING AND
MANIPULATION
. USAGE OF VECTOR CLASS
/ INTERFACES AND PACKAGES
'&
T"READ BASED APPLICATION AND
E0CEPTION "ANDLING
'' T"READ BASED S$NC"RONI1ATION
'% TE0T FILES( DISPLA$ COP$ AND COUNT
') FRAMES AND VARIOUS CONTROLS
'* DIALOGUE BO0 AND MENUS
'+ COLORS AND FONTS USING APPLET
',
DRA2ING VARIOUS S"APEA USING
GRAP"ICAL STATEMENT
'- PANELS AND LA$OUT
'. SIMPLE CALCULATOR
'/
USAGE OF BUTTONS3LABELS AND TE0T
COMPONENTS
%&
USAGE OF RADIO BUTTONS3C"ECKBO0
AND C"OICELIST
SUBSTRING REMOVAL USING BUFFER CLASS
i$port 0a&a)io)89
i$port 0a&a)lan")89
class s#!str
:
p#!lic static &oid $ain(.trin" ar"s;<+ thro,s IOE2ception
:
.trin" $ainstr's#!str'res#lt9
int i9
Inp#t.trea$Reader ir=ne, Inp#t.trea$Reader(.yste$)in+9
B#fferedReader !r= ne, B#fferedReader(ir+9
.yste$)o#t)println(>Enter the $ain strin"* >+9
$ainstr=!r)readLine(+9
.yste$)o#t)println(>enter the .#!strin"* >+9
s#!str=!r)readLine(+9
.yste$)o#t)println(>?n RE.%LT ?n@+9
.yste$)o#t)println(>The Gi&en .trin"@ A$ainstrA @?n@+9
.yste$)o#t)println(>the Gi&en s#!strin" > As#!strA >?n@+9
do
:
i=$ainstr)inde2Of(s#!str+9
if(iB=16+
:
res#lt=$ainstr)s#!strin"(5'i+9
res#lt=res#ltA$ainstr)s#!strin"(iAs#!str)len"th(++9
$ainstr=res#lt9
C
C
,hile(iB=16+9
.yste$)o#t)println(>After Re$o&al@ A$ainstrA >?n@+9
C
C
C*?-oc#$ents And .ettin"s?Ad$inistratorDcd 0Esd/6)F)5?!in
C*?0Esd/6)F)5?!inD0a&ac s#!str)0a&a
C*?0Esd/6)F)5?!inD0a&a s#!str
O%TP%T
Enter The Mainstrin"* 3orld 3ide 3e!
Enter the s#!strin"*3
RE.%LT
The "i&en Mainstrin" * 3orld 3ide 3e!
The Gi&en .#!strin"*3
After Re$o&al* orld ide e!
AREA AND PERIMETER OF T"E TRIANGLE
i$port 0a&a)io)89
i$port 0a&a)lan")89
p#!lic class trian"le
:
p#!lic static &oid $ain(.trin" ar"s;<+thro,s IOE2ception
:
Inp#t.trea$Reader ir=ne, Inp#t.trea$Reader (.yste$)in+9
B#fferedReader B#ffer.trea$= ne, B#fferedReader(ir+9
do#!le !'h's6'sE'sG'a'p9
.trin" str9
.yste$)o#t)println(>?n?t ENTER THE BREA-TH* ?n?t@+9
str=B#fferstrea$)readLine(+9
!=Inte"er)parseInt(str+9
.yste$)o#t)println(>?n?t ENTER THE HEIGHT* ?n?t@+9
str=B#fferstrea$)readLine(+9
h=Inte"er)parseInt(str+9
.yste$)o#t)println(>?n?t ENTER EACH .I-E OI THE TRIANGLE* ?n?t@+9
str=B#fferstrea$)readLine(+9
s6=Inte"er)parseInt(str+9
str=B#fferstrea$)readLine(+9
sE=Inte"er)parseInt(str+9
str=B#fferstrea$)readLine(+9
sG=Inte"er)parseInt(str+9
a=5)J8!8h9
p=s6AsEAsG9
.yste$)o#t)println(>?n?t THE AREA I. * > AaA >?n?t@+9
.yste$)o#t)println(>?n?t THE PERIMETER I. *@ ApA >?n?t@+9
C
C
C*?-oc#$ents And .ettin"s?Ad$inistratorDcd 0Esd/6)F)5?!in
C*?0Esd/6)F)5?!inD0a&ac trian"le))0a&a
C*?0Esd/6)F)5?!inD0a&a trian"le
O%TP%T
ENTER THE BREA-TH* F
ENTER THE HEIGHT* K
ENTER THE EACH .I-E OI THE TRIANGLE*

E
G
F
THE AREA I.*64)5
THE PERIMETER I.*L)5
RANDOM NUMBER GENERATION USING
RANDOM CLASS
i$port 0a&a)io)89
i$port 0a&a)lan")89
i$port 0a&a)#til)89
class rando$
:
p#!lic static &oid $ain(.trin" ar"s;<+ thro,s IOE2ception
:
int a;<'!;<'c;<'i'09
int te$p'$a29
.trin" str9
.yste$)o#t)println(MEnter the Ter$s* M+9
B#fferedReader !r=ne, B#fferedReader(ne,
Inp#t.trea$Reader(.yste$)in++9
str=!r)readLine(+9
$a2=Inte"er)parseInt(str+9
a=ne, int;$a2<9
!=ne, int;$a2<9
c=ne, int;$a2<9
Rando$ rnd=ne, Rando$(+9
.yste$)o#t)println(M?n?t Rando$ N#$!er Generated ?n?tM+9
for(i=59iN$a29iAA+
:
a;i<=!;i<=c;i<=rnd)ne2tInt(+9
.yste$)o#t)println(iAM?tMAa;i<+9
C
.yste$)o#t)println(M?n Rando$ N#$!er In Ascendin" Order?tM+9
for(i=59iN$a29iAA+
:
for(0=iA690N$a290AA+
:
if(!;i<D!;0<+
:
te$p=!;i<9
!;i<=!;0<9
!;0<=te$p9
C
C
C
for(i=59iN$a29iAA+
.yste$)o#t)println(iAM?tMA!;i<+9
.yste$)o#t)println(M?t Rando$ N#$!er In -escendin"
Order?tM+9
for(i=59iN$a29iAA+
:
for(0=iA690N$a290AA+
:
if(c;i<Nc;0<+
:
te$p=c;i<9
c;i<=c;0<9
c;0<=te$p9
C
C
C
for(i=59iN$a29iAA+
.yste$)o#t)println(iAM?tMAc;i<+9
C
C
C*?-oc#$ents And .ettin"s?Ad$inistratorDcd 0Esd/6)F)5?!in
C*?0Esd/6)F)5?!inD0a&ac rando$)0a&a
C*?0Esd/6)F)5?!inD0a&a rando$
O%TP%T
ENTER THE TERM.*
J
RAN-OM N%MBER GENERATE-
5 E6G7GJ5JJF
6 64JK7GLL4F
E 1EGF64G4L5
G 1K76L5K4KL
F 67JFJ4G7E
RAN-OM N%MBER IN A.CEN-ING OR-ER
5 1K76L5K4KL
6 1EGF64G4L5
E 67JFJ4G7E
G 64JK7GLL4F
F E6G7GJ5JJF
RAN-OM N%MBER IN -E.CEN-ING OR-ER
5 E6G7GJ5JJF
6 64JK7GLL4F
E 67JFJ4G7E
G 1EGF64G4L5
F 1K7EL5K4KL
USAGE OF CALENDAR CLASS
i$port 0a&a)io)89
i$port 0a&a)#til)89
p#!lic class calend
:
p#!lic static &oid $ain(.trin" ar"s;<+thro,s IOE2ception
:
.trin" $onths;< = : > JAN @' @ IEB @ '@ MAR @' > APR @'
> MAO > ' > J%N > ' > J%L >' > A%G >'
> .EP @' > OCT @' >NOV @'@ -EC @C9
Calendar c=Calendar)"etInstance(+9
.yste$)o#t)println(>?n?t CALEN-AR OI THE .O.TEM?n?t@+9
.yste$)o#t)println(>?n?t C%RRENT -ATE ?n?t@+9
.yste$)o#t)println(>?n ?t> A$onths;c)"et(Calendar)MONTH+<A
> > Ac)"et(Calendar)-ATE+A > >Ac)"et(Calendar)OEAR+ A >?n?t@+9
.yste$)o#t)println(>?n?t C%RRENT TIME ?n?t@+9
.yste$)o#t)println(>?n ?t> Ac)"et(Calendar)HO%R+A
> *>Ac)"et(Calendar)MIN%TE+A >* >Ac)"et(Calendar).ECON-+A+9
c)set(Calendar)HO%R'65+9
c)set(Calendar)MIN%TE'E5+9
c)set(Calendar).ECON-'JJ+9
.yste$)o#t)println(>?n?t %P-ATE- TIME ?n?t@+9
.yste$)o#t)println(>?n ?t> Ac)"et(Calendar)HO%R+A
> *>Ac)"et(Calendar)MIN%TE+A >* >Ac)"et(Calendar).ECON-+A+9
C
C
C*?-oc#$ents And .ettin"s?Ad$inistratorDcd 0Esd/6)F)5?!in
C*?0Esd/6)F)5?!inD0a&ac calend))0a&a
C*?0Esd/6)F)5?!inD0a&a calend
O%TP%T
CALEN-AR OI THE .O.TEM
C%RRENT -ATE
MAR 6E E565
C%RRENT TIME
65*EK*K
%P-ATE- TIME
65*E5*JJ
IMAGE MANIPULATION FOR POINT CLASS
i$port 0a&a)applet)89
i$port 0a&a)a,t)89
i$port 0a&a)a,t)e&ent)89
p#!lic class i$a" e2tends Applet
:
Point p6'pE'pG9
int 26'2E'2G'y6'yE'yG9
.trin" str9
p#!lic &oid init(+
:
p6=ne, point(75'6J5+9
pE=ne, point(K5'K5+9
pG=ne, point(+9
setBac/"ro#nd(Color)"reen+9
C
&oid setpos(+
:
26=(int+p6)"etP(+9
y6=(int+p6)"etO(+9
2E=(int+p6)"etP(+9
yE=(int+p6)"etO(+9
2G=(int+p6)"etP(+9
yG=(int+p6)"etO(+9
C
p#!lic &oid paint(Graphics "+
:
p6)$o&e(75'6J5+9
pE)$o&e(K5'K5+9
setpos(+9
")setColor(Color)yello,+9
")dra,O&al(26'y6'2E'yE+9
")setColor(Color)Red+
")fillO&al(26'y6'2E'yE+9
p6)$o&e(6J6'6J5+9
setpos(+9
")setColor(Color)!l#e+9
")dra,Rect(26'y6'2E'yE+9
")detColor(Color)!l#e+9
")fillRect(26'y6'2E'yE+9
p6)$o&e(665'6J5+9
p6)$o&e(6J5'665+9
p6)$o&e(6L5'6J5+9
")setColor(Color)oran"e+9
p6)$o&e(EG6'6J5+9
setpos(+9
")fillO&al(26'y6'2E'yE+9
")setColor(color)!lac/+9
")dra,.trin"(>IMAGE@'E55'655+9
C
C
Q8Napplet code=@i$a")0a&a@ ,idth=F55 hei"ht=F55D NQappletD8Q

EMAIL ADDRESS SORTING AND MANIPULATION

i$port 0a&a)io)89
class e$ail
:
.trin" na$e9
.trin" $ailid9
.trin" ser&er9
.trin" p,9
B#fferedReader !r9
Iile file!09
int siRe9
p#!lic e$ail(+ thro,s IOE2ception
:
!r=ne, B#fferedReader(ne,+
Inp#t.trea$Reader(syste$)in++9
Iileo!0=ne, Iile(Me$ailid)datM+9
siRe=(int+fileo!0)len"ht(+9
C
&oid add(+thro,s IOE2ception
:
Iile3riter f,=ne, Iile3riter(Me$ailid)datM'tr#e+9
char rec;<=ne, char;J5<9
.yste$)o#t)println(MEnter na$e*M+9
na$e=!r)readLine(+9
.yste$)o#t)println(Enter e$ailid*M+9
e$ailid=!r)readLine(+9
.yste$)o#t)println(MEnter ser&er*M+9
ser&er=!r)readLine(+9
.yste$)o#t)println(Menter pass,ord*+9
p,=!r)readLine(+9
na$e)"etChars(5'na$e)len"th(+'rec'5+9
siReA=49
$ailid)"etChars(5'$aildid)len"th(+'rec'4+9
siReA=659
ser&er)"etChars(5'ser&er)len"th(+'rec'EJ+9
siReA=659
p,)"etChars(5'p,)len"th(+'rec'GJ+9
siReA=6J9
f,),rite(rec+9
.yste$)o#t)println(+9
f,)close(+9
C
p#!lic &oid dra,Line(+9
:
.yste$)o#t)println(+9
for(int i=59iN459iAA+
:
.yste$)o#t)println(M8M+9
C
.yste$)o#t)println(+9
C
&oid display(+thro,s IOE2ception
:
IileReader fr=ne, IileReader(fileo!0+9
B#fferedreader !ri=ne, B#fferedReader(fr+9
.trin" file=!ri)readLine(+9
char rec;<=ne, char;J5<9
.yste$)o#t)println(+9
dra,Line(+9
.yste$)o#t)println(MNAME?t EMAILI-?t
.ERVERNAME?t PA..3OR-M+9
.yste$)o#t'println(+9
dra,Line(+9
for(int i=59iNsiRe9iA=J5+
:
file)"etChars(i'iAJ5'rec'5+9
.yste$)o#t)println(+9
C
dra,Line(+9
fr)close(+9
C
&oid $odify(+thro,s IOE2ception
:
.yste$)o#t)println(Menter $ailSid to !e
$odified*M+9
.trin" id=!r)readLine(+9
IileReader fr=ne, IileReader(fileo!0+9
B#fferedReader !ri=ne, B#fferedReader(fr+9
char rec;<=ne, char;J5<9
.trin" file=!ri)readLine(+9
for(int i=59iNsiRe9iA=J5+
:
file)"etChars(i'iAJ5'rec'5+9
Q8.trin" recid=ne, .trin"(rec'6J'65+98Q
.trin" recid=ne, .trin"(rec+9
rec=ne, char;J5<9
if(recid)tri$(+)co$pareTo(id)tri$(++==5+
:
fr)close(+9
Rando$AccessIile raf=ne,
Rando$AcceaaIile(Me$ailid)datM'Mr,M+9
.yste$)o#t)println(MEnter na$e*M+9
na$e=!r)readLine(+9
.yste$)o#t)println(Enter e$ailid*M+9
e$ailid=!r)readLine(+9
.yste$)o#t)println(MEnter ser&er*M+9
ser&er=!r)readLine(+9
.yste$)o#t)println(Menter pass,ord*+9
p,=!r)readLine(+9
na$e)"etChars(5'na$e)len"th(+'rec'5+9
$ailid)"etChars(5'$ailid)len"th(+'rec'6J+9
ser&er)"etChars(5'ser&er)len"th(+'rec'EJ+9
p,)"etChars(5'p,)len"th(+'rec'F5+9
raf)see/(i+9
raf),riteBytes(ne, .trin"(rec++9
raf)close(+9
.yste$)o#t)println(MRECOR- MO-IIIE-*M+9
ret#rn9
C
C
fr)close(+9
.yste$)o#t)println(MRecord is not fo#ndM+9
C
&oid delete(+thro,s IOE2ception
:
.yste$)o#t)println(Menter e$ailid to !e deletedM+9
.trin" id=!r)readLine(+9
IileReader fr=ne, IileReader(fileo!0+9
B#fferedReader !ri=ne, B#fferedReader(fr+9
char rec;<=ne, char;J5<9
.trin" file=!ri)readLIne(+9
for(int i=59iNsiRe9iA=J5+
:
file)"etChars(i'iAJ5'rec'5+9
.trin" recid=ne, .trin"(rec'6J'65+9
if(recid)tri$(+)co$pareTo(id)tri$(++==5+
:
fr)close(+9
Iile3riter f,=ne, Iile3riter(fileo!0+9
char c;<=file)toCharArray(+9
f,),rite(c'5'i+9
f,),rite(c'iAJ5'siRe1(i=J5++9
siRe1=J59
f,)close(+9
.yste$)o#t)println(M-ELETE-M+9
ret#rn9
C
C
fr)close(+9
.yste$)o#t)println(Mrecord is not fo#ndM+9
ret#rn9
C
C9
p#!lic class $ailE
:
p#!lic static &oid $ain(.trin" ar"s;<+thro,s IOE2ception
:
e$ail o!0=ne, e$ail(+9
B#fferedReader !r=ne, B%fferedReader(ne,
Inp#t.trea$Reader(.yste$)in++9
char ch=TyT9
,hile(ch==TyT+
:
int choice9
.yste$)o#t)println(M?n?t?t PROIILE ?n?nM+9
.yste$)o#t)println(M?t 6)AdditionM+9
.yste$)o#t)println(M?t E)-eletionM+9
.yste$)o#t)println(M?t G)EditM+9
.yste$)o#t)println(M?t F)-isplayM+9
.yste$)o#t)println(M?t J)E2itM+9
.yste$)o#t)println(M?n?n?t?t Enter Oo#r choiceM+9
try
:
choice=Inte"er)parseInt(!r)readLine(++9
C
catch(E2ception e+
:
choice=59
C
s,itch(choice+
:
case 6*
o!0)add(+9
!rea/9
case E*
o!0)delete(+9
!rea/9
case G*
o!0)$odify(+9
!rea/9
case F*
o!0)display(+9
!rea/9
case J*
ch=TnT9
!rea/9
defa#lt*
:
.yste$)o#t)println(MILLEGAL OPTIONM+9
C
ret#rn9
C
C9
C
C
C*?-oc#$ents and .ettin"s?Dcd?0Esd/6)F)5?!in
C*?0Esd/6)F)5?!inD0a&ac e$ail)0a&a
C*?0Esd/6)F)5?!inD0a&a e$ail
O#tp#t*
PROIILE
6)addition
E)deletion
G)edit
F)display
J)e2it
Enter yo#r choice
6
Enter na$e
II BCA
Enter ser&er
.. JAIN
Enter e$ail1id*
IIbcajaincollege@yahoo.co)in
PROIILE
6)addition
E)deletion
G)edit
F)display
J)e2it
Enter yo#r choice*
6
Enter na$e*
a!cd
Enter e$ail1id*
a!cdef"Uyahoo)co$
Enter ser&er*
J/
Enter pass,ord*
L/
PROIILE
6)addition
E)deletion
G)edit
F)display
J)e2it
Enter yo#r choice
F
8888888888888888888888888888888888888888888888
NAME EMAILI- .ERVERNAME
PA..3OR-
8888888888888888888888888888888888888888888888
IIIBCA iib4566675i8499ege:y5;.4m ss0ain
/li
a!cd 5b4de#g:y5;.4m 0/
l/

PROIILE
6)addition
E)deletion
G)edit
F)display
J)e2it
Enter yo#r choice
E
Enter e$ailid to !e deleted
a!cdef"Uya0/hlUyshoo)co$
Record is not fo#nd
PROIILE
6)addition
E)deletion
G)edit
F)display
J)e2it
Enter yo#r choice
G
Enter e$ailid $odified*
da0ds0/sUyahoo)co$
Record is not fo#nd*

PROIILE
6)addition
E)deletion
G)edit
F)display
J)e2it
Enter yo#r choice
J

STRING MANIPULATION
i$port 0a&a)io)89
i$port 0a&a)lan")89
class strin
:
char a;<=ne, char;E5<9
char !;<=ne, char;E5<9
char c;<=ne, char;E5<9
int l'/'I'0'L'fla"=59
&oid "et(+ thro,s IOE2ception
:
B#fferedReader !r=ne, B#fferedReader(ne,
Inp#t.trea$Reader(.yste$)in++9
.yste$)o#t)println(> Enter the first strin"*@+9
.trin" ss=!r)readLine(+9
l=ss)len"th(+9
ss)"etChars(5'l'a'5+9
.yste$)o#t)println(>Enter the second strin"*@+9
.trin" sa=!r)readLine(+9
/=sa)len"th(+9
sa)"etChars(5'/'!'5+9
C
&oid len"th(+
:
int lenl=59
for(i=59iNl9iAA+
:
lenl=lenlAi9
C
.yste$)o#t)println(>Len"th of the first .trin"@ AlenlA@?n?t@+9
int l=59
for(i=59iN/9iAA+
:
L=LA69
C
.yste$)o#t)println(>?n?t Len"th of the first .trin"@ALA@?n@+9
C
Void re&erse(.trin" str+
:
char c;<=str)toCharArray(+9
for(i=c)Len"th1l9iD=59i11+
:
.yste$)o#t)println(c;i<+9
C
C
&oid conca(+
:
int 0=59
for(i=59iNl9iAA+
:
c;0<=a;i<9
0AA9
C
for(i=59iN/9iAA+
:
c;0<=!;i<9
0AA9
C
for(i=59iN09iAA+
:
.yste$)o#t)println(c;i<+9
C
C
&oid co$p(+
:
if(l==/+
:
for(i=59iNl9iAA+
:
if(a;i<B=!;i<+
:
fla"=i9
!rea/9
C
C
if(fla"==i+
:
.yste$)o#t)println(>the .trin"s are eV#al@+
C
C
else
:
.yste$)o#t)println(>The .trin"s are not EV#al@+
C
C
&oid rep(.trin" str'Char ch'int n+
:
char c;<=str)toCharArray(+9
.yste$)o#t)println(>Replaced .trin"@+9
c;n16<=ch9
for(i=59iNc)Len"th9iAA+
:
.yste$)o#t)println(c;i<+9
C
C
&oid eV#(+
:
for(int i=59iNL9iAA+
:
if((!yte+a;i<B=(!yte+!;i<+
:
Ila"=I9
!rea/9
C
C
if(fla"==i+
:
.yste$)o#t)println(>?n the cases are not EV#al@+9
C
else
:
.yste$)o#t)println(>?n the cases are EV#al@+9
C
C
&oid lo,(.trin" str+
:
char c;<=str)toCharArray(+9
for(i=59iNc)Len"th9iAA+
:
int $=c;i<9
if($D4FW$NL6+
:
c;i<=(char+($AGE+9
C
C
.yste$)o#t)println(c+9
C
&oid #p(.trin" str+
:
char c;<=str)toCharArray(+9
for(i=59iNc)len"th9iAA+
:
int $=c;i<9
if($DL4W$N6EG+
:
c;i<=(char+($1GE+9
C
C
.yste$)o#t)println(c+9
C
C
class str$an
:
p#!lic .tatic &oid $ain(.trin" ar"s;< + thro,s IOE2ception
:
char ch9
.yste$)o#t)println(>?t?n strin" $anip#lation@+9
B#fferedReader p= ne, B#fferedReader(ne,
Inp#t.trea$Reader(.yste$)in+9
.trin" a = ne, strin(+9
a)"et(+9
.yste$)o#t)println(>.trin" len"th@+9
a)len"(+9
.yste$)o#t)println(>.trin" Concatenation@+9
a)conca(+9
.yste$)o#t)println(>.trin" Co$parison@+9
a)co$p(+9
.yste$)o#t)println(>.trin" EV#i&alent@+9
a)eV#(+9
B#fferedReader !r=ne, B#fferedReader(ne,
Inp#t.trea$Reader(.yste$)in++9
.yste$)o#t)println(>enter the strin" to chan"e case@+9
.trin" ss=!r)readLine(+9
.yste$)o#t)println(>?n.trin" %pper Case@+9
a)#p(ss+9
.yste$)o#t)println(>?n.trin" lo,er Case@+9
a)lo,(ss+9
.yste$)o#t)println(>?n.trin" Re&erse@+9
a)re&erse(ss+9
.yste$)o#t)println(>Character Replace$ent@+9
B#fferedReader r = ne, B#fferedReader(ne,
Inp#tstrea$Reader(.yste$)in++9
.yste$)o#t)println(>Enter the .trin" for character Replace$ent@+9
.trin" sa=!r)readLine(+9
.yste$)o#t)println(>?nEnter the position@+9
Int s=inte"er)parseInt(p)readline(++9
.yste$)o#t)println(>Enter the replace$ent &aria!le@+9
Chi=(char+.yste$)in)read(+9
.yste$)o#t)println(>The Replace$ent &aria!les*@Achi+9
a)rep(sa'chi's+9
C
C
C*?-oc#$ents And .ettin"s?Ad$inistratorDcd 0Esd/6)F)5?!in
C*?0Esd/6)F)5?!inD0a&ac strin )0a&a
C*?0Esd/6)F)5?!inD0a&a strin
O%TP%T
.trin" $anip#lation
Enter the first strin"
hi hello
Enter the .econd .trin"
I a$ La&anya
.trin" len"th
Len"th of the first strin" K
Len"th of the .econd strin" 6E
h
i
h
e
l
o
o
i
a
$
l
a
&
a
n
y
a
.trin" co$parison
The strin"s are not eV#al
.trin" EV#i&alence
The cases are not eV#al
Enter the .trin" to chan"e case
ss0ain
.trin" %ppercase
..JAIN
.trin" Lo,ercase
ss0ain
.trin" re&erse
n
i
a
0
s
s
character Replace$ent
Enter the strin" for Character replace$ent
ss0ain
Enter the position
4
Enter the replace$ent &aria!le*8
Replaced .trin"
s
s
0
a
i
8
USAGE OF VECTOR CLASS
i$port 0a&a)#til)89
class &ector
:
p#!lic static &oid $ain(.trin" ar"s;<+
:
Vector &=ne, Vector(G'E+9
.yste$)o#t)println(>?n?t INITIALIXE * > A&)siRe(+A@?n?t@+9
.yste$)o#t)println(>?n?t INITIAL CAPACITO*@ A&)capacity(+A
>?n?t@+9
&)addEle$ent(ne, Inte"er(6++9
&)addEle$ent(ne, Inte"er(E++9
&)addEle$ent(ne, Inte"er(G++9
&)addEle$ent(ne, Inte"er(F++9
.yste$)o#t)println(>?n?t CAPACITO AITER IO%R A--ITION*@
A&)capacity(+A >?n?t@+9
&)addEle$ent(ne, -o#!le(J)FJ++9
.yste$)o#t)println(>?n?tC%RRENT CAPACITO*@ A&)capacity(+A
>?n?t@+9
&)addEle$ent(ne, -o#!le(4)5K++9
&)addEle$ent(ne, Inte"er(7++9
.yste$)o#t)println(>?n?tC%RRENT CAPACITO*@ A&)capacity(+A
>?n?t@+9
&)addEle$ent(ne, Iloat(L)F++9
&)addEle$ent(ne, Inte"er(65++9
.yste$)o#t)println(>?n?tC%RRENT CAPACITO*@ A&)capacity(+A
>?n?t@+9
&)addEle$ent(ne, Inte"er(66++9
&)addEle$ent(ne, Inte"er(6E++9
.yste$)o#t)println(>?n?t IIR.T ELEMENT*
> A(Inte"er+&)firstEle$ent(+A@?n?t@+9
.yste$)o#t)println(>?n?tLA.T ELEMENT*
> A(Inte"er+&)lastEle$ent(+A@?n?t@+9
if(&)contains(ne, Inte"er(G+++9
.yste$)o#t)println(>?n?t VECTOR CONTAIN. G?n?t@+9
En#$eration en#$=&)ele$ents(+9
.yste$)o#t)println(>?n?t ELEMENT. IN VECTOR* ?n?t@+9
,hile(en#$)hasMoreEle$ents(++
.yste$)o#t)println(en#$)ne2tEle$ent(+ A > @+9
.yste$)o#t)println(+9 CC
C*?-oc#$ents And .ettin"s?Ad$inistratorDcd 0Esd/6)F)5?!in
C*?0Esd/6)F)5?!inD0a&ac &ector)0a&a
C*?0Esd/6)F)5?!inD0a&a &ector
O%TP%T
INITIALIXE*5
INITIAL CAPACITO* G
CAPACITO AITER IO%R A--ITION* J
C%RRENT CAPACITO* J
C%RRENT CAPACITO* 7
C%RRENT CAPACITO* L
IIR.T ELEMENT* 6
LA.T ELEMENT* 6E
VECTOR CONTAIN. G
ELEMENT. IN VECTOR*
6
E
G
F
J)FJ
4)5K
7
L)F
65
66
6E
PACKAGE
pac/a"e MyPac/9
class Balance
:
.trin" na$e9
-o#!le !al9
Balance(.trin" n'do#!le !+9
:
na$e=n9
!al=!9
C
&oid sho,(+
:
if(!alN5+
:
.yste$)o#t)println(>a@+9
.yste$)o#t)println(na$eA@*Y@A!al+9
C
C
class Acco#ntBalance
:
p#!lic static &oid $ain(.trin" ar"s;<+
:
Balance c#rrent;<=ne, Balance;G<9
c#rrent;5<=ne, Balance(>)J)IIEL-ING@'6EG)EG+9
c#rrent;6<=ne, Balance(>3ILL TELL @'6J7)5E+9
c#rrent;E<=ne, Balance(>TOM JAC.ON@'16E)GG+9
for(int i=59iNG9iAA+
c#rrent;i<)sho,(+9
C
C
C*?-oc#$ents and strin"s?Ad$inistratorDcd 0Esd/6)F)5?!in
C*? 0Esd/6)F)5?!inD$d MyPac/
C*? 0Esd/6)F)5?!inD0a&ac MyPac/?Acco#ntBalance)0a&a
C*? 0Esd/6)F)5?!inD0a&a MyPac/)Acco#ntBalance
O%TP%T
)J)IIEL-ING*Y 6EG)EG
3ILL TELL*Y 6J7)5E
a
TOM JAC.ON*Y 16E)GG
DIALOG BO0 AND MENUS
i$port 0a&a)a,t)89
i$port 0a&a)a,t)e&ent)89
i$port 0a&a)a,t)datatransfer)M9
p#!lic class C#tAPast e2tends Ira$e
:
Men#Bar $!Ane, Men#Bar(+9
Men# file=ne, Men#(MIileM+9
Men# edit=ne, Men#(MEditM+9
Men#Ite$ c#t=ne, Men#Ite$(Mc#tM+9
Men#Ite$ copy=ne, $en#Ite$(McopyM+
Men#Ite$ paste=ne, $en#Ite$(MpasteM+9
Men#Ite$ ite$E'ite$F9
Te2tArea te2t=ne,Te2tArea(E5'E5+9
Clip!oard clipcd="etTool/it(+)"et.yste$Clip!oard(+9
p#!lic C#tAPast(+
:
file)add(ite$E=ne, Men#Ite$(MOpenM++9
file)add(ite$F=ne, Men#Ite$(M.a&eM++9
$!)add(file+9
c#t)addActionListener(ne, C#tL(++9
copy)addActionListener(ne, Copy(++9
paste)addActionListener(ne, paste(++9
edit)add(c#t+9
edit)add(copy+9
edit)add(edit+9
setMen#Bar($!+9
add(te2t'BorderLayo#t)CENTER+9
MyMen#Handler handler=ne, MyMen#Handler(this+9
ite$E)addActionListener(handler+9
ite$F)addActionListener(handler+9
C
class CopyL i$ple$ents ActionListener
:
p#!lic &oid actionPerfor$ed(ActionE&ent e+
:
.trin" selection=te2t)"et.electedTe2t(+9
.trin".election clip.trin"=ne, .trin".election(selection+9
clip!d)setContents(clip.trin"'clip.trin"+9
C
C
class C#tl i$ple$ents ActionListener
:
p#!lic &oid actionPerfor$ed(ActionE&ent e+
:
.trin" selection=te2t)"et.electedTe2t(+9
.trin".election clip.trin"=ne, .trin".election(selection+9
clip!d)setContents(clip.trin"'clip.trin"+9
te2t)repalceRan"e(MM'te2t)"et.election.tart(+'te2t)"etselection
End(++9
C
C
class PasteL i$ple$ents ActionListener
:
p#!lic &oid actionPerfor$ed(ActionE&ent e+
:
Tranfera!le
clip-ata=clip!d)"etContents(C#tAPast)this+9
try
:
strin" clip.trin"=(strin"+
clip-ata)"etTransfer-ata(-ataIla&or)strin"Ila&or+9
te2t)replaceRan"e(clip.trin"'te2t)"et.election.tart(+'
te2t)"et.electionEnd(++9
C
catch(E2pression e2+
:
.yste$)o#t)println(Mnot strin" fla&orM+9
C
C
C
p#!lic static &oid $ain(strin" ar"a;<+
C#tAPast cp=ne, C#tAPast(+9
cp)add3indo,Listener(ne, 3indo,Adapter(++9
:
p#!lic &oidd ,indo,Closin"(3indo,E&ent e+
:
.yste$)e2it(5+9
C
C+9
cp)set.iRe(G55'E55+9
cp)setVisi!le(tr#e+9
C
C
class MyMen#Handler i$ple$ents ActionListener
:
C#tAPast $en#fra$e9
p#!lic MyMen#Handler(c#tAPast $en#Ira$e+
:
this)$en#Ira$e=$en#Ira$e9
C
p#!lic &oid actionPerfor$ed(ActionE&ent ae+
:
if(ae)"etActionCo$$and(+==MopenM+
:
Iile-ialo" fd=ne,
Iile-ialo"($en#Ira$e'MopenM'Iile-ialo")LOA-+9
fd)setVisi!le(tr#e+9
C
if(ae)"etActionCo$$and(+==Msa&eM+
:
Iile-ialo" fd=ne,
Iile-ialo"($en#Ira$e'Msa&eM'Iile-ialo").AVE+9
fd)setVisi!le(tr#e+9
C
C
C
T"READ BASED APPLICATION AND
E0CEPTION "ANDLING
i$port 0a&a)a,t)89
i$port 0a&a)applet)89
p#!lic class .a$ple e2tends Applet i$ple$ents
R#nna!le
:
.trin" $s"=@HELLO 3ORL-@9
Thread t=n#ll9
int stat9
!oolean .topfla"9
p#!lic &oid init(+
:
setBac/"ro#nd(Color)cyan+9
setBac/"ro#nd(Color)red+9
C
p#!lic &oid r#n(+
:
char ch9
for(99+
:
try
:
repaint(+9
Thread)sleep(EJ5+9
ch=$s")charAt(5+9
$s"=$s")s#!strin"(6'$s")len"th(++9
Thread)sleep(EJ5+9
ch=$s")charAt(5+9
$s"=$s")s#!strin"(6'$s")len"th(++9
$s"A=ch9
if(.topfla"+
!rea/9
C
catch(Interr#ptedE2ception e+
:
C
C
C
p#!lic &oid stop(+
:
.topfla"=tr#e9
t=n#ll9
C
p#!lic &oid paint(Graphics "+
:
")dra,.trin"($s"'6J5'6J5+9
C
C
Q8Napplet code=@.a$ple)0a&a@,idth=455 hei"ht=FJ5DNQappletD8Q
T"READ BASED S$NC"RONI1ATION
i$port 0a&a)io)89
i$port 0a&a)a,t)89
class sycl e2tends Thread
:
p#!lic &oid displ(+thro,s E2ception
:
.yste$)o#t)println(>HELLO@+9
Thread)sleep(6555+9
.yste$)o#t)println(>3ORL-@+9
Thread)sleep(6555+9
C
p#!lic static synchroniRed &oid disp(+thro,s E2ception
:
.yste$)o#t)println(>3ITH .ONCHRONIXATION@+9
.yste$)o#t)println(>HELLO@+9
.yste$)o#t)println(>3ORL-@+9
Thread)sleep(6555+9
C
p#!lic &oid r#n(+
:
try
:
displ(+9
Thread)sleep(6555+9
.yste$)o#t)println(+9
disp(+9
C
catch(E2ception e+
:C

C
C
class .ynchron
:
p#!lic static &oid $ain(.trin" ar"s;<+thro,s
IOE2ception
:
sycl o!06=ne, sycl(+9
sycl o!0E=ne, sycl(+9
.yste$)o#t)println(>APPLICATION. %.ING
.ONCHRONIXATION@+9
.yste$)o#t)println(>APPLICATION. 3ITHO%T
%.ING .ONCHRONIXATION@+9
o!06)start(+9
o!0E)start(+9
C
C
C*?-oc#$ents and strin"s?Ad$inistratorDcd
0Esd/6)F)5?!in
C*? 0Esd/6)F)5?!inD0a&ac .ynchron)0a&a
C*? 0Esd/6)F)5?!inD0a&a .ynchron
O%TP%T
APPLICATION. %.ING .ONCHRONIXATION
APPLICATION. 3ITHO%T %.ING .ONCHRONIXATION
HELLO
HELLO
3ORL-
3ORL-

3ITH .ONCHRONIXATION
HELLO
3ORL-
3ITH .ONCHRONIXATION
HELLO
3ORL-

INTERFACE
i$port 0a&a)io)89
i$port 0a&a)lan")89
interface Area
:
final static float pi=G)6Ff9
float co$p#te (float 2 ' float y+9
C
class rectan"le i$ple$ents Area
:
p#!lic float co$p#te(float 2 ' float y+
:
ret#rn(28y+9
C
C
class circle i$ple$ents Area
:
p#!lic float co$p#te(float 2 ' float y+
:
ret#rn(pi8282+9
C
C
class InterfaceTest
:
p#!lic static &oid $ain(.trin" ar"s;<+
:
rectan"le rect=ne, rectan"le(+9
circle cir=ne, circle(+9
Area area9
area = rect9
.yste$)o#t)println(>AREA OI RECTANGLE I. *
> Aarea)co$p#te(65'E5++9
area=cir9
.yste$)o#t)println(>AREA OI CIRCLE I. * > Aarea)co$p#te(65'5++9
C
C
C*?-oc#$ents And .ettin"s?Ad$inistratorDcd?0Esd/6)F)5?!in
C*?0Esd/6)F)5?!inD0a&ac InterfaceTest)0a&a
C*?0Esd/6)F)5?!inD0a&a InterfaceTest
O%TP%T
AREA OI RECTANGLE I.* E55)5
AREA OI CIRCLE I.*G6F)5

SIMPLE CALCULATOR
i$port 0a&a2)s,in")89
i$port 0a&a2)s,in")JOptionPane9
i$port 0a&a)a,t)89
i$port 0a&a)a,t)e&ent)89
i$port 0a&a)applet)89
p#!lic class Calc#lator e2tends JApplet
:
P#!lic &oid init(+
:
Calc#latorPanel calc=ne, Calc#latorPanel(+9
"etContentPane(+)add(calc+9
C
C
Class Calc#latorPanel e2tends JPanel i$ple$ents ActionListener
:
J!#tton
n6'nE'nG'nF'nJ'n4'n7'nK'nL'n5'pl#s'$in#s'$#l'di&'dot'eV#al9
static JTe2tIield res#lt=ne, JTe2tIield(>5@'FJ+9
static .trin" lastCo$$and=n#ll9
JOptionPane p=ne, JOptionPane(+9
do#!le preRes=5'secVal=5'res9
pri&ate static &oid assi"n(.trin" no+
:
I i((res#lt)"etTe2t(++)eV#als(>5@++
Res#lt)setTe2t(no+9
else if(lastCo$$and==@=@+
:
Res#lt)setTe2t(no+9
lastCo$$and=n#ll9
C
else
res#lt)setTe2t(res#lt)"etTe2t(+Ano+9
C
p#!lic Calc#latorPanel(+
:
setLayo#t(ne, BorderLayo#t(++9
res#lt)setEdita!le(false+9
res#lt)set.iRe(G55'E55+9
add(res#lt'BorderLayo#t)NORTH+9
JPanel panel=ne, JPanel(+9
Panel)setLayo#t(ne, GridLayo#t(F'F++9
n7=ne, JB#tton(>7@+9
panel)add(n7+9
n7)addActionListener(this+9
nK=ne, JB#tton(>K@+9
panel)add(nK+9
nK)addActionListener(this+9
nL=ne, JB#tton(>L@+9
panel)add(nL+9
nL)addActionListener(this+9
di&=ne, JB#tton(>Q@+9
panel)add(di&+9
di&)addActionListener(this+9
nF=ne, JB#tton(>F@+9
panel)add(nF+9
nF)addActionListener(this+9
nJ=ne, JB#tton(>J@+9
panel)add(nJ+9
nJ)addActionListener(this+9
n4=ne, JB#tton(>4@+9
panel)add(n4+9
n4)addActionListener(this+9
$#l=ne, JB#tton(>8@+9
panel)add($#l+9
$#l)addActionListener(this+9
n6=ne, JB#tton(>6@+9
panel)add(n6+9
n6)addActionListener(this+9
nE=ne, JB#tton(>E@+9
panel)add(nE+9
nE)addActionListener(this+9
nG=ne, JB#tton(>G@+9
panel)add(nG+9
nG)addActionListener(this+9
$in#s=ne, JB#tton(>1>+9
panel)add($in#s+9
$in#s)addActionListener(this+9
dot=ne, JB#tton(>)@+9
panel)add(dot+9
dot)addActionListener(this+9
n5=ne, JB#tton(>5@+9
panel)add(n5+9
n5)addActionListener(this+9
eV#al=ne, JB#tton(>=@+9
panel)add(eV#al+9
eV#al)addActionListener(this+9
pl#s=ne, JB#tton(>A>+9
panel)add(pl#s+9
pl#s)addActionListener(this+9
add(panel'BorderLayo#t)CENTER+*
C
p#!lic &oid actionPerfor$ed(ActionE&ent ae+
:
if(ae)"et.o#rce(+==n6+ assi"n(>6@+9
else if(ae)"et.orce(+==nE+ assi"n(>E@+9
else if(ae)"et.orce(+==nG+ assi"n(>G@+9
else if(ae)"et.orce(+==nF+ assi"n(>F@+9
else if(ae)"et.orce(+==nJ+ assi"n(>J@+9
else if(ae)"et.orce(+==n4+ assi"n(>4@+9
else if(ae)"et.orce(+==n7+ assi"n(>7@+9
else if(ae)"et.orce(+==nK+ assi"n(>K@+9
else if(ae)"et.orce(+==nL+ assi"n(>L@+9
else if(ae)"et.orce(+==n5+ assi"n(>5@+9
else if(ae)"et.orce(+==dot+
:
If(((res#lt)"etTe2t(++)inde2Of(>)@++==16+
res#lt)setTe2t(res#lt)"etTe2t(+A@)@+9
C
else if(ae)"et.o#rce(+==$in#s+
:
preRes=-o#!le)parse-o#!le(res#lt)"etTe2t(++9
lastCo$$and=@1>9
res#lt)setTe2t(>5@+9
C
else if(ae)"et.o#rce(+==di&+
:
preRes=-o#!le)parse-o#!le(res#lt)"etTe2t(++9
lastCo$$and=@Q>9
res#lt)setTe2t(>5@+9
C
else if(ae)"et.o#rce(+==eV#al+
:
secVAl=-o#!le)parse-o#!le(res#lt)"etTe2t(++9
if(lastCo$$and)eV#als(>Q@++
res=preResQsecVal9
else if(lastCo$$and)eV#als(>8@++
res=preRes8secVal9
else if(lastCo$$and)eV#als(>1@++
res=preRes1secVal9
else if(lastCo$$and)eV#als(>A@++
res=preResAsecVal9
res#lt)setTe2t(> >Ares+9
lstCo$$and=@=@9
C
Else if(ae)"et.o#rce(+==$#l+
:
preRes=-o#!le)parse-o#!le(res#lt)"etTe2t(++9
lastCo$$and=@8@9
res#lt)setTe2t(>5@+9
C
else if(ae)"et.o#rce(+==pl#s+
:
preRes=-o#!le)parse-o#!le(res#lt)"etTe2t(++9
lastCo$$and=@A@9
res#lt)setTe2t(>5@+9
C
C
C
Q8Napplet code=@Calc#lator)0a&a hei"ht=G55 ,idth=E55DNQappletD8Q
FRAMES AND VARIOUS CONTROLS
i$port 0a&a)a,t)89
i$port 0a&a)applet)89
i$port 0a&a)a,t)e&ent)89
p#!lic class fra$edo e2tends Applet i$ple$ents
ActionListener
:
B#tton !9
Te2tfield t9
p#!lic &oid init(+
:
Ira$e f=ne, Ira$e(>IRAME-O@+9
f)setLayo#t(ne, GridLayo#t(E'E++9
f)set.iRe(E55'E55+9
!=ne, B#tton(>IIB)sc(c)s+@+9
f)add(!+9
!)addActionListener(this+9
t=ne, Te2tIield(J5+9
f)add(t+9
f)sho,(+9
C
p#!lic &oid actionPerfor$ed(ActionE&ent e+
:
if(e)"et.o#rce(+==!+
:
t)setsetTe2t(>ALL THE .T%-ENT. ARE RAN HOL-ER.@+9
C
C
C
Q8Napplet code=@fra$edo)0a&a@ ,idth=F55 hei"ht=F55D NQappletD8Q
COLORS AND FONTS
i$port 0a&a)a,t)89
i$port 0a&a)applet)89
p#!lic class color e2tends Applet
:
P#!lic &oid paint(Graphics "+
:
setBac/"ro#nd(Color)cyan+9
Iont f=ne, Iont(>Ti$es ne,
ro$an@ ' font)BOL-AIont)ITALIC'E5+9
")setIont(f+9
")dra,.trin"(>Li&e happy And Let Happy@'F5'E5+9
")setcolor(Color)pin/+9
C
C
Q8Napplet code=@Colorr)0a&a@ hei"ht=F55 ,idth=F55D NQappletD8Q
VARIO%. .HAPE. %.ING GRAPHICAL .TATEMENT
i$port 0a&a)a,t)89
i$port 0a&a)applet)89
p#!lic class Color-e$o e2tends Applet
:
p#!lic &oid paint(Graphics "+
:
Color c6=ne, Color(EJJ'655'655+9
Color cE=ne, Color(655'EJJ'655+9
Color cG=ne, Color(655'655'EJJ+9
")setColor(c6+9
")dra,line(5'5'655'655+9
")dra,Line(5'655'655'5+9
")setColor(cE+9
")dra,line(F5'EJ'EJ5'6K5+9
")dra,Line(75'L5'F55'F55+9
")setColor(cG+9
")dra,line(E5'6J5'F55'F5+9
")dra,Line(J'EL5'K5'6L+9
")setColor(Color)red+9
")dra,O&al(65'65'J5'J5+9
")fillO&al(75'L5'6F5'655+9
")setColor(Color)!l#e+9
")dra,O&al(6L5'65'L5'G5+9
")dra,Rect(65'65'45'J5+9
")setColor(Color)cyan+9
")fillRect(655'65'45'J5+9
")dra,Ro#ndRect(6L5'65'45'J5'6J'6J+9
C
C
Q8Napplet code=@Color-e$o)0a&a@ ,idth=F55 hei"ht=F55D NQappletD8Q
PANELS AND LA$OUT
i$port 0a&a)a,t)89
i$port 0a&a)a,t)e&ent9
i$port 0a&a)ap;plet9
p#!lic class Graphicsde$ e2tends Applet
:
p#!lic Graphicsde$ (+
:
set.iRe(G55'G55+9
setLayo#t(ne, GridLayo#t(E'6++9
add(ne, Rectan"les(++9
add(ne, O&als(++9
setVisi!le(tr#e+9
C
C9
class Rectan"les e2tends Panel
:
p#!lic Rectan"les(+
:
setBac/"ro#nd(Color)pin/+9
C
p#!lic &oid paint(Graphics "+9
:
Rectan"le !o#nds="etBo#nds(+9
int 2=5'y=59
int ,=!o#nds),idth169
int h=!o#nds)hei"ht169
for(int i=59iN659iAA+
:
")dra,Rect(2'y','h+9
2A=659
yA=659
,1=E59
h1=E59
C
C
C9
class O&als e2tends Panel
:
p#!lic O&als(+
:
setIore"ro#nd(Color)!l#e+9
setIore"ro#nd(Color)!lac/+9
C
p#!lic &oid paint(Graphics "+
:
Rectan"le !o#nds="et!o#nds(+9
int 2=5'y=59
int ,=!o#nds),idth169
int h=!o#nds)hei"ht169
for(int i=59iN659iAA+
:
")dra,O&al(2'y','h+9
2A=659
yA=659
,1=659
h1=E59
C
C
C9
Q8Napplet code=@Graphicsde$)0a&@ ,idth=G55 hei"ht=G55D NQappletD8Q
%.AGE OI B%TTON.'LABEL. AN- TEPT COMPONENT.
i$port 0a&a)a,t)89
i$port 0a&a)a,t)e&ent)89
i$port 0a&a)applet)89
p#!lic class Te2tfield e2tends Applet i$ple$ents ActionListener
:
Te2tIield na$e ' pass9
B#tton Lo"in9
P#!lic &oid init(+
:
La!el na$ep=ne, La!el(>%.ERNAME*@'La!el)RIGHT+9 La!el
passp=ne, La!el(>PA..3OR-*@'La!el)RIGHT+9
na$e=ne, Te2tIield(E5+9
pass=ne, Te2tIield(65+9
Lo"in=ne, B#tton(>Lo"in@+9
add(na$ep+9
add(na$e+9
add(passp+9
add(Lo"in+9
na$e)addActionlistener(this+9
pass)addActionListener(this+9
Lo"in)addActionListener(this+9
C
p#!lic &oid actionPerfor$ed(ActonE&ent ae+
:
repaint(+9
C
p#!lic &oid paint(Graphics "+
:
")dra,.trin"(>%.ERNAME*@ Ana$e)"etTe2t(+'4'655+9
")dra,.trin"(>PA..3OR-*@ Apass)"etTe2t(+'4'655+9
CC
Q8Napplet code=@Te2tfield)0a&a@ ,idth=F55 hei"ht=F55D NQappletD8Q
USAGE OF RADIO BUTTONS3
C"ECKBO0 AND C"OICELISTS

i$port 0a&a)a,t)89
i$port 0a&a)a,t)e&ent)8 9
i$port 0a&a)applet)8 9
p#!lic class chec/option e2tends Applet i$ple$ents
Ite$Listener
:
pri&ate Te2tIield tf 9
pri&ate Chec/!o2 !old'italic 9
pri&ate Chec/!o2Gro#p colorGro#p 9
pri&ate Chec/!o2 !l#e'"reen'red 9
p#!lic &oid init(+
:
tf=ne, Te2tIield(>-IVOA@'E5+9
tf)setIont(ne, Iont(>serif@'Iont)PLAIN'6F++ 9
add(tf+ 9
!old=ne, Chec/!o2(>BOL-@+9
!old)addIte$Listener(this+9
add(!old+9
italic=ne, Chec/!o2(>ITALIC@+9
italic)addIte$Listener(this+9
add(italic+9
colorGro#p = ne, Chec/!o2Gro#p(+9
!l#e=ne, Chec/!o2(>Bl#e'color"ro#p'tr#e+9
!l#e)addIte$Listener(this+9
add(!l#e+9
"reen=ne, Chec/!o2(>Green@'color"ro#p'false+9
"reen)AddIte$Listener(this+9
add("reen+9
red=ne, Chec/!o2(>red'color"ro#p'false+9
red)addIte$Listener(this+9
add(red+9
setBac/"ro#nd(Color)!l#e+9
C
p#!lic &oid ite$.tateChan"ed(Ite$E&ent e+
:
int &Bold = (!old)"et.tate(+ZIont)BOL-*Iont)PLAIN+9
int &Italic=(italic)"et.tate(+ZIont)ITALIC*Iont)PLAIN+9
if(e)"et.o#rce(+==!l#e+
:
setBac/"ro#nd(Color)!l#e+9
C
elseif(e)"et.o#rce(+=="reen+9
:
setBac/"ro#nd(Color)"reen+9
C
elseif(e)"et.o#rce(+==red+
:
setBac/"ro#nd(Color)red+9
C
C
C
Q8Napplet code=@Chec/option)0a&a@ ,idth=GJ5 hei"ht=6J5D NQappletD8Q
TE0T FILES(COP$ING3DISPLA$ING AND COUNT
i$port 0a&a)io)89
p#!lic calss 3ordCo#nt
:
pri&ate static &oid lineco#nt(strin" fNa$e'B#fferedReader in+thro,s
IOE2ception
:
lon" n#$Char=59
lon" n#$Line=59
lon" n#$3ords=59
.trin" line9
do
:
line=in)readLine(+9
if(lineB=n#ll+:
n#$CharA=line)len"th(+9
n#$3ordsA=,ordco#nt(line+9
n#$LineAA9
C
C
,hile(lineB=n#ll+9
.yste$)o#t)println(>IILE NAME*@AfNa$e+9
.yste$o#t)println(>N%MBER OI CHARACTER.*@An#$Char+9
.yste$o#t)println(>N%MBER OI 3OR-.*@An#$3ords+9
.yste$o#t)println(>N%MBER OI LINE.*@An#$Line+9
C
pri&ate static &oid lineco#nt(.trin" str$an+
:
B#fferedReader in=n#ll9
try
:
IileReader flleReader=ne, IileReader(>str$an)0a&a@+9
in=ne, B#fferedReader(fileReader+9
lineco#nt(>str$an)0a&a'@in+9
C
catch(IOE2ception e+
:
e)print.tac/ Trace(+9
C
C
pri&ate static lon" ,ordco#nt(.trin" line+
:
lon" n#$3ords=59
int inde2=59
!oolrean pre&3hite.pace=tr#e9
,hile(inde2Nline)len"th(++:
char c=line)charAt(inde2AA+9
Boolean c#rr3hite.pace=Character)is3hitespace[9
if(pre&3hite.paceWWBc#rr3hite.pace+
:
n#$3ordsAA9
C
pre&3hite.pace=c#rr3hite.pace9
C
ret#rn n#$3ords9
C
p#!lic static &oid $ain(.trin";<ar"s+
:
lon" n#$Char=59
lon"n#$Line=59
.trin" line9
try
:if(ar"s)len"th==5+
:
B#ffererdReader in=ne, B#fferedReader(ne,
Inp#t.trea$Reader(.yste$)in++9
line=in)readLine(+9
n#$Char=line)len"th(+*
if(n#$CharB=5+
:
n#$Line=69
C
.yste$)o#t)println(>N%MBER OI CHARACTER.*@An#$Char+9
.yste$)o#t)println(>N%MBER OI 3OR-.*@A,ordco#nt(line++9
.yste$)o#t)println(>N%MBER OI LINE.*@An#$Line+9
C
else
:
for(int i=59iNar"s)len"th9iAA+
:
lineco#nt(ar"s;i<+9
C C C
Catch(IOE2ception e+
:
print.tac/Trace(+9
C C C
C*?-oc#$ents and .ettin"s?Ad$inistratorDcd?0Eds/6)F)5?!in
C*? 0Eds/6)F)5?!inD0a&ac 3ordCo#nt)0a&a
C*? 0Eds/6)F)5?!inD0a&a 3ordCo#nt) Hello
O%TP%T
IILENAME*str$an)0a&a
N%MBER OI CHARACTER.*G5J
N%MBER OI 3OR-.*ELJ
N%MBER OI LINE.*674

USAGE OF BUTTONS,LABELS AND TEXT COMPONENTS
i$port 0a&a)a,t)89
i$port 0a&a)a,t)e&ent)89
i$port 0a&a)applet)89
p#!lic class Te2tfield e2tends Applet i$ple$ents ActionListener
:
Te2tIield na$e ' pass9
B#tton Lo"in9
P#!lic &oid init(+
:
La!el na$ep=ne, La!el(>%.ERNAME*@'La!el)RIGHT+9 La!el passp=ne,
La!el(>PA..3OR-*@'La!el)RIGHT+9
na$e=ne, Te2tIield(E5+9
pass=ne, Te2tIield(65+9
Lo"in=ne, B#tton(>Lo"in@+9
add(na$ep+9
add(na$e+9
add(passp+9
add(Lo"in+9
na$e)addActionlistener(this+9
pass)addActionListener(this+9
Lo"in)addActionListener(this+9
C
p#!lic &oid actionPerfor$ed(ActonE&ent ae+
:
repaint(+9
C
p#!lic &oid paint(Graphics "+
:
")dra,.trin"(>%.ERNAME*@ Ana$e)"etTe2t(+'4'655+9
")dra,.trin"(>PA..3OR-*@ Apass)"etTe2t(+'4'655+9
C
C
Q8Napplet code=@Te2tfield)0a&a@ ,idth=F55 hei"ht=F55D NQappletD8Q

You might also like