0% found this document useful (0 votes)
50 views41 pages

Java QB Answers

The document discusses Java threading and the creation of multiple threads to execute processes in parallel. It covers concepts such as thread creation, synchronization, and event handling in Java applications. Additionally, it provides code examples and explanations of how to manage threads and their execution states.

Uploaded by

srizzza07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
50 views41 pages

Java QB Answers

The document discusses Java threading and the creation of multiple threads to execute processes in parallel. It covers concepts such as thread creation, synchronization, and event handling in Java applications. Additionally, it provides code examples and explanations of how to manage threads and their execution states.

Uploaded by

srizzza07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Mid-2 Java 3 %ont} cron bo creale ine Mreads esing Renaabh i Sa Ing, emenfs Roane : ‘9 vale vod donc) 0 00 Fete C Fraga yo Mreads"); 3 clans Four Thypads t Poble Dabh t Mala m 2 new Maine, void mak Crig a7gsty Thread t, = nee Thread (im); Thiead ly = new Thread (my; thread 4,= 10 rhread Gm; Thread by = new thread (my; by - sdaw¢ » be -sharhey, ts Sor oo; I +4. Shark cy, woliifracessiog wuphirle Processos/ Pes are added fo the Syshem fo Srcteate He comfobing Powe oP He syshen 9 muhhle Poocemes ave execokd Ina Paratiel fashton , ) Puocems oe 45 Hime- Contunting W) Ja rditrecening mony Peocees ave execuked stnel dencous Ly SD Melt Procening vepurres a StaniPicaat amount oP Kme | and Levee ino. #esorrees Dhow many weys are Porstsle ) gi farerBale ee moll Bocening Sli threading. ii y| faa Parattced Fashton fo Pc) "age | He Hhaovol He System, | 1 molliple pheaeads ae execohed fa «a Parallel Padhorn, af 3) Thread creahon’ % oa aan ’s Kime carry “dom Mttthrcodig mony Herecds ave exccoled simul laneorsby, s) cltithreading veg ulreg ee Te Felourey bo cereale : Pn fara fo Create mebitreadry Pragrams viscets He IPasence behveen Kem. xeculng more an one Krted Hood enerssty ts Favwun ee arbi Revealing ’ ° ‘mPorh gaya. of Random; Vj Program “8 Wimber Crenevaloy extends thread L é A Pos Ap. bt Rendom Fand = new arden); ny ' t etch . voll twa c) Fb num = vand. nex! fa) L100); [Fandom nimbey 0-99 Sysheon. oot. Prath, (Va Genevaled number trem); P Cum 1.2. >= 0) ¢ ' new sgvare Thread (nom). slarbo $ . ‘ hie t neo cube Thread Crum) .sJar/c); so thread, Doe Cove), calch (ont TP led Exc Phi, o) t . Syslem. 00). Pret Sy &, 5 y 4 day Speare Thread ex bry rad é fol nom , Spvare Thad (to) » ae | \ poole vold tency { a ’ AN ‘ sysher ook F801 Csgvore pee a ” + Coum them); } 7 a) / day cube Krad exkads aad : " [ \ Sn) nem; | cobe Thread Cy} 7) t nem iny j poblic vod genes fe Sydheo ov). Prinidy Cee oP" tata? t's = 4 Coumtrumr num); j 4 pool. chor, bbrh read Example f 5 Whe stabi voll mom Cabra a ; ge? Go vr her Generator by «new Nember Generaherl). . ‘ sShertey , i 3 DE. les, Sova snehsokizalon wth Exomph 7 Prdaontralfon ha technigue Jerough hth we en . ——_—e—eeee ’ fhreads On, Kh of Mba L mobile Vreads oF anos ¢ 70 a 2. area. One Yrread oll bt enlex Sndile the apcteosie X ©? Synchaonfeapt,, can be brcedly (vided Sole feo or ' Method eed syed ror cabiea, e. Choct Devel Synchdon' 2a bon ti > ow ge leclere “y methed’ as & peleor Ud? a toody fy dve00 red mda, > eychronteed method 8 vsed b hock an objed L oO, faved Tes ource. [Link], ¥ on robe t synehnont, zed wold Pain) tah h Cal ny ¢ Rea lin) Po) p tees ten é dysbenn. ool rtd Cats), y, r™% £ Thread. Durlted, j catch CExtePhon €) a4 £ syker ook Piteth le, j 3 4 3 j ayy myrhreads erlends ‘ Thread f soy ye ND wp ti , rhtead, (Tables, \y ; fate. a f * wal Jhis bebe ’ ; : ye j 4 puke ved tency 3 ' sey WE Shas, 9 Woy [Link] “PS BY : ahd / / : : \ i] cles myereed 2 ehhends treed yd ft table ts Ta | | 4 threadg Crubh 4) , : \ Mes heb voy 3 \ VRS OE bas VG Poble vor Yenc) { + Path Table Gecsy 5 ay ’ w re) > v sos yn oe cow Inbyrlrtes 00 tbl. Ab verd wai “a a) ral, obs = “north oe : MG thread Le new ney Th reed, (oss), 144 thread fo = new atytb reeds Cob )s ‘ y t, -shovlo); oe Pu) £ te ser cs; a \e Ss 20 ag 100 » edi the compbrle bp, gel of Hreod. ( f Fn Cece Java ,@ Haead aloays exit Fr “y one f Le Peheowirg Shaka $e ". New 2. Ache r’3. ie Leoathen immed Petes GS. Teaminaled 6 ad Jats Exthanalvon of Phxenf thre Ne? ~ Whenever a new fread % ctakd Uf alow ; Ga He neo Shale For a Hread a freed £, tn He new Gi He tole fas nod been awn pel, Active, When a fread Snvokes Ye tadthe rteHheod , % moves fyom fee new dake be ache lak. the achve shake conlatos poo sheds 128k PL. One Re | qeaneble | and He ther % reonkag, 4 hy A Phreod Hab 8s wendy fo yen % Men Moed Me rurale shake. \ eT eT | r when Ae Jhreod 4 He (Pv », 2 moves Form He pnb yn" | vrnoble to Ke gong tale 1 ft \ . ) locked oF woot Reg TOlenever a real % Snaclte Py a Pon x fp) Hine (ool feamonerbly) Hen, Fea We Haead 9s In He Wicked Shale or $1 In We wetting Dale, , Timed. wothinge Somefines (2 Pirg Br Vw, ho Sereabon \ 1 example 1% Bend (15 nome A K04 enfered Ke \ teal secon of a Code and & & nob willing fo dea } dhal chal secon, - Termoatedy A Haead of He Pato? vechews he kerminahon slate becaug q We adsons. . ’ 4 wer shasthc)” eting chu coating Q. ene) exiled cho y A — Le le oP oh Teed erminabed (seed fi) A vnft J fle 9 Coser deb, abon -eveat modell ei aa Exon i eve a aay bh bond >The teyakon veal Model $n fa us fverts (Like buon cles , mouse moves hey PerniN Pe tent by Sn 601 we Dlicakona, 7” exe a7¢ Hree main Far. Even) source Tle 6, v & ca cA r a buon cMhck Grerles en even). FF confab deta abou! He even) Cewy bafe AP event, Vine source , elo) Cx Adlon Even! Cov befor Mets) Mouse Cunt bfed on ahich He even) occorsy Q} Buon , Texteteds, Frome) key Event. veoh Pakner (Eun) kanashs) “700 Folerface Hat defies Me mebked be Jonah a ParKulay hyhe of wend x + Achoalethiney Moses iikeney ie fSlener. 0 g g ‘ cxplota various Legooh managers Fa faves h > the La oul Managers are used & agtonge 9m fone A \ . 4 j fo a Patkichay renner. he java Heyer! eranogers Provides us fo (ontmaS te ; \ \ Wy Positieg Me sre oP the camPenenly tr Go Frames wl j laser! eden fi an Poletbace Hal % fo tlemented by, au He dana ob Layout ynaragers : : pes oP La ooh Wearager Ro parte LE Le \ 7 9 order Le-gous yas ; » RV! ’ \ 3. frebdlegoo) uw cetdiquaut \a 6 Gaou Logout 9 foo 6. drviddy boyout Flow whe Cb teu fs @ stnple Leyous moreger Vhab anrages ComPonents in a too, Well fy iad wrabtey Wee Foe 8 needed. Corder lagousy. v ~ Verde Layee) dtl Ue Conlotrer 2th Pre refiong NORTH Sout EAsr Wes gy Clureg a p, a ” GaP oh vents ComPonenfa Ga a tid oth ethan 70. of gous f cobomas Bed Cak ey Pr kb re con bold a comPonenl, g ‘ JS ) vi}. abou varia tex! comPontenhy 2h Conta RRND hoc con Pontat Meal “allots : eter b enter on single Pine fal acd eb? ie Aol Ted Fahy bers pechrabon TPeblic hey Texted extends Tex) Combonenl i? Weel A ‘el day Lord Frechory D Text rfeldcy © crates a nec ard bextheld ‘Cmbenep) yo ? tex Feld she tel) + 7/ tak a new Jexd Pols wipe, te given Spring texl fo be Stayed 8) Tex? LS (nd columns) JL tondlacd) a nes tex} field Cembly) wi gen naof Cokerns. U) TAD FAS (sting ber, od collemas)e HE lord bevy bexl PLL wip, We j columns Le tdpp) 9) texkptetd ay Mebeds h 2 Fol yteokoms0yp 7 Plékes He ro. of cobrony Ft exh Field, a new fren beth and fi 2h Qk coboms + Fl Sel the ne. of\ cele xa ey seb’ for! ava. adh. 5 jf clos Text eteld Example i \ walt Shale old mata Ghiy rg am P 2 ne Prome Cree} Fug Crample'), textfield by pbes ro ae by enue textFteld Cvelcome’ Jp Gite" ti se Bourds(S0., loo ; 900 , 30); ‘ tiene Text Fels Ceese-'$"); +1 su Bourda (s0 \$0), 200) 30), Po add Gag MN Pradd (be) s5 % YY Psetstre. (400, 400), P. sbogou (neler, Braet : J j Schutt De Uyvey ,' onteh Tet Feld Examtle — 22% | | Weeheome to Jove Boiyl] | | er toler] fn (er Fiely OMrerkat rds, als af? Wad weg : hes Degoot _ Le Grd ayoot. 1 t ? Arian 4 comPonenh ba bo | Arranges combenen ts h é @ 90 when space | 4 Pixed itd of) Vows ° y ‘Puy , moves po next Line and colems y 2 Com Panent Veet Hote Orbeared YAM lomboninpy are Ted Cropral) ae. | & epval Site. , » Sv PPor jy oltanmerd Lone LEFT, | 3) wo olgrmend svPPor)_ q ENTER , and LIGHT every cede % Placd %) Patou fs Plerisle p10. op “) bayou! fe Srey wy Y tomPoneny Per Fow Vatiou | entborm y each cell koh 9 oe Legout L, Ponel exactly one Lombonerd hd Avebep Dist be exhichy 0h g He Preyrommer 16) €xelatn fo chtatl aboos Panel 2 Phe Fanl ts Ihe contatrer thal devin’ Genob, wos bar, border DP mene dar 2 tan have Oke lomfrreny Lite bHon , beets —> Pblic chy Pandk eslends conbatner ln planinh Fr} n ) Accestste Feegtam imfor! . [Link]).*; Pobbic ow Panel Example rattramil eg ) y j rh ih cow 2 200 Poume Chavel fanth P= 100 Panele), ‘Cram pb, YD se) bors (uo, £0, 200, too) pie] Bayi aroun Color gray); won b, = new Gribon CBobon); 1 St Bourdd (50100, fo, Jo) { 1. SbBack yround (colet .yelios) ; Hon by =rerfulton (Oulton 2"), 9 Sth Bounds Cie9,, 100, P0,30)- yo" bo. sep Backgtoond (color. fem ay Pad (biz [Link] (ba); Pads (P); | P se/sPoe (400, woo), “ Psclvo wut Crud) |[Link] vise be Owe); j ie Doh void main (Srtng apes) neo Panel Gamble oy, j 5 ¥ V Z & ,, of evenly és ven gave Facgtam & Fonds Aepoot enh , 7 CAbstrack ndom role) fn favo, fey evink ML be Forde peyriord foto) Vrim He vser Yo ed Chey even} ee AY S method St Cnvebed!wohen hey % Fretted wad Bele, A lbeeuat 0 rt "S mbes K Pavoked wher a bey fs ele cdl 4 Ty Ped Chey eve0) 5) 4 B "% mehod ts Srvobed when ¢ bey Peon and rebore P ombinadvon ells fn @ wntode ichavather a7 iF °, J [Link]}.€ > fool clays be Virer éxampla extends Frame fn Clenenh beyonce 1m Por}. babel 1; ie: “Text Arta awa: 4 Listerex Exanpl. o moe cnew babel); t. se/Bourds (90,50, |00, a0), | | avea anew Text Adeac); |) awa. st} Bourcs (90 , 90 , 300, 300); , ren. add byl skenex At), O07 . ) (area); ep size( bee, 400) + stage? (neko ed vst be bro; hic vobd da Pretted Chegevend e) uu text Chey Premed "Lb ‘ ‘ hake votd poy keleased Cry veal e) ul Text Cry Pebrased’); alt Vohd bey rye Coyevea °) fa rect Chey ryfed dy 5 Peblie dab vee) \gneh (he, fd main (Slalngh J a7 1) t go new op ilner €£am ple ou 4 5 ¥ | oul fos bey Poaed, | Ks ts sand || - Priap | } | 2M er He SPavcere oP ADT clon beverly 4 F487 Cpperracl wieder toobt) ts 0 AB bo devely p Grrathical usex Faferbace (Ou) 0% eb ho Pa APL ica hon, Sn gore. ) j 7 Tava AwWT torbonen ave abbbam _ deferdend Conk " are ee according fo We Vile fp ohh Tava AT Agerarchy [Wiad] , 7 iP se) [Frame ! DPalo i eedez\ 13) covite @ Foegnaen to hendbe moose woh? > za Awt (Abalrad prdouw Teoh KL) fn Se Movie wel are fardled uy Libner frledace, aed Paton riley Mevselibener and Aectetobenl bene x B ae for! avers Bioing- SS *, fn) Gaveaah.®; fovl java x Nay even). *, fort java awh. event, *, Inyy ptovse Even) ber foxmey Qelends TF rome Planer Movselistener Label L a wb bic Hose veg feboemer cy i sd pel Loseoferabon (SFrame. Ext7-o- CLosé)y Sesire (300 300); Ye bagoet (a Flaw bayoub Clrabeyedt. CEvTERY)2 f ene Thabeley; Feat Pe neo FeAl C verdana’, Fen}. Bol b, 90); 4 “Slog ind Cle. CLE); add(f), 8d Mouse 1°, beney Cts), Sehveig dy CSref', 5 y Pade © vol Pt 9, POU EK ech, Croosetie ab om) "3A Tee) Cotouse Ex ed”); vot lose Crleved Crowe Cvenk a) i eyed Feet Chote Onkeved Y. pr. ved ed (ovsePreted (Moule Even) mm SA Text Carouge Pretted’); PO 08d pron Mitel Crouebrans ”) ". 8/ text CMote eifed"|, Publi. s Jase. old mata (Sy euse Evert Pee rmey mer opt 74 74) Stee eet trend perbermes cy, = => The fava! Packere contons chante, G0! ComPonent nheding tentdinerst Frame, Panel , 0: ¥ vores mmbonen t OoHon , Label, TeKbfilld , Texh10a, checkboy ote, Lt), scVollbar . eke. Yiere are Leer types oP _tendetners In tava pho. nohndowd fone Frame dialog \ Vind? ene bats. you rash ye Prame, Male 07 aacher Books 2 oy creahig a Window. The Panel fs He Hhytatag Kab doen’) lon/ din ah bar, border ox mene bekten BEA Dah deed othen tomfonea She TOE he. Frome i \ The yy He contotrer Mal tnlotr Hihe ber and bor de, 7 and “f tan have menu bars. HL tan have obker Com banen oneatt Uke bolton , bextfelds Sere hley te. Frome», ; smash ofdehy wed conhabney white éahes 3 427 Qi ajo, « wader 43° fe Cohbdbner Hal have no bordest andi ' ty oer oo abel > Ze 2, *s ected Io tirly tex 01 PnPormabon Ulex > “q ’s won nbervachive Does pop accef) user tnbop Does nos Gere very Sed Texto) ge text C) >t ts simph Jel, a0 bordex 4 Seba Om Pg re dehoeen he bly and bots Colton. ___+___, IL be used b rf 4 an akfon Lhen cht > Tbh Pnferachve > ActelH wer Pnfo)- Hreugh chicks > Gererafe Adon Cj vente | When Mefed > Add A hoo likened) 3 tt Jateh ? Looks Hike a putk Seon, wk 30 tye 5) Hoo mony wos an Here Jo Exelen 42, dela hY These are foo Piionery Foame fe 2 ir Para dg gy ex bending a ¥ fm For} Seva. aw}.*, ee wos be Cweale an fur He Frome clou Caherilence vee) > Thes aPProach Yavallios Cray, . F000). Frome. Create @ Aw7 PromeB Of 2 7602 chery pa) lk bean nyfreme whrds Frome’ pili: nytrone Ciriig Hehe) c fer Uiths; bultee (400, 900; erloyou) (need Flocd pele b debe 10; J flo eo ee Sabie votd maty Ceey cs #42) Niw My Fome Cry Cet Her ee by creoling wa ftbance ob Me frome chs » F cha rick, / Svabres creahing an object the Save-a0, Frame ayy CdLdy within grofer day b1 melhod. 0 sohorp J 200. 00.K; i chew sinthe Frome Public abe, vot) mak i Frame lize oy) b, /, Tome -peo Foom (staple A7 Frome”), OMe. seh iene (400, 300; st Lepeod Crew hecteyoute)) o vitbte Cree); 5" oni} Y 4 Der Le, abel Revemeler faning fo aftleh fe < Partom> fq fs a sob he P he yattled> fag. the < Patoms ag comlains boo abfytbokes sname and vthe ; hey ae used fo Ady He mame of be Paromenh and py, valve oP Hf, (fovomebey wesheel ively exenble, he. Faron bags hes Passing neme and ofe Paromefers Las Ca below, Lean . Patomname =“aame’ yale eS galentZ The Gl(rem ela) mbhod ob fe pptl) hos con be ened bo Velve He ~aramelers fasted Vrom be HTML Page 4 Fregrom Infor! fava-owp*; Ymfor} . Sava .aveler*, fobbic bats appr Ael extends pals t shiing n; Gaba fy foblic voed Pries t ne gelfaremcterCrone'); Ps glberemeler Cage’) ly ys he voks Paint (Gaothies 9) 1 7 waltig (tore fs 2" 4 , ,20) ; 70 pvoas tig Age és 3449/90, 40); « ePibd Code." ny Alle” heigl! =" 300° wd 2500” > 4fatam nome =*pome” Valve =a" yane” /> 4 fave name Sagely ve yp" fy £6 GE) ‘ [a Act > oulfet v Sivan? 18, whl tan AALS? exph, ue Ls ge SL WHS win net sted 2 >An ated ts embeded #n on HIML fege vig Pe Aopled bey. meons Hal tan ables Fregron & Ae tombbrabon\ of Jara Program and HL Progtom. 4 attled tr @ favo Pooprom Wal ton be embedded Ini @ | J oy 2b Page > ¥ tng ade He wb brwswer and works on He Leas sh e « Lh eycha of an aftld %, managed by he AHL ~The ene Con), Hainer. ' E ° sora, APL. ppl ben AR), 2 AL ape) are sub - chases (ther Soech ly Pintire 9 nol tend - alone Aigytems ‘ they Tr ey ie “Ke, Heheds ppp se cg late > seen # * eb browser 97 on AAS viewer. tater The fn%h0) mehod % the [Py) hod be tor bal FoWastoes He opPleg j ~? The wed bacirser aon He Infhey milked ctihlin Je apely —> slodor 1 The slater meked corporns fe aha! code of fe gph and ath He Fle}. H7 HF Snvohed Surmedtabely ober He Pc) mead ts Orval <2 tt F500 tnadkve Shale unpey He tn? 0) melbod & ay) -75)efO- ‘Tle shoe thed Sob fe exceohon oD yy ates phen we I” Sack fo fal fege. He are) jae * He dest meebo! Aes He ope) obfer 5 whi 4 a, poe conrel Shoat the afd once %}.98\ detVroyed. 4 faint ok He fobr) ¢) meKeol ichoy to te Gvvathies laa Pn fovn Hts execoled, aber tee arte) mehhed and then the kaos a1 fled Wncleos 0% terized, Trost hy re) AME) Becy cle tehnds ppp) t é poblic vaes Fad YS 7 5 ? ete f saad Winialized obfects 5 Able vob) Dawe i WU code fo fark be ot 4 y NG Posie vote Pate) CGnoblicy ¢) t Ja He tho Pes : 3 Poblt. rots dof) t Nie b sht He opfld, rie vets Leap eyo W Code 5 J ’ tiltoy He aptlal behvcen Oi renal Teele, ” Avple vals, are gos) kite @ Sova Paogrom Hal ton be CXecofe/ Prdefen dently hou) esioy Me tb browser ? Wae @ PPL cabon Progrom Br es a moore) mehod &, Pes execohon fore con accey ad of rerovrce avatles th, On Sy3hem > APO ons Can execek He Programs Prom We Local Sy them > FF comot wn on Ls own, Pl reeds TRE fe exc fe 19) Ex Alec, '") I Faome ®) Thanel 3) SAPP Le 4) T%aog 9) Seanvas pon £ MENA? Angle — ~> Ahly ave tate swe w Progtoms Hal exc cer fyn fo be Pytloded wh He Hat web docomen). > The apple! does nol Hep oe He motoc) wnethed for tts | Pralead Pnvdt) meh Ps vegofued. deve Pacall execuhion ? aptleh dor’ AK and nelwork accey } b> sply Cen ondy ec | baeceer ~ shecth, servke ¥ l-> % ty vnebL fo conned Pe ater c — ty He vertous ComPonerty -of # stp, Servers gqme.- % 2, ° 0 : favax. sang IF tome hee "sy @ Lyfe of Onloiney ohieg, e het He fave awh .Foome bbe ‘ gfreme works ike We moby vinden Dhere comPonnly) i Nye Labels , boWora , dex Weeks are adled ito create a ‘oon —— a Brrr. - | onb}tocer—— Pes cdithion x uy Ny vome® >A Condtrcs a neo brome hal ts “sed invisighe ’ rome (sisieg Vb) 97 treales a new, foBhally tavicls be eeiN4 Wh pe specthed Uiph, Corssids a new, Fo Maley Ponies Prone WY He steed oioner frome. [SeOndtred anced, Pobttell torial Lrome \ Pee yFveme asvte)| oth He ‘sbecthed 1M and amen Frome Pan he Tanck ts He Sempplad contabrer choos >t boherty We SeorPoneshs claws and Paotles a sloce ley "0 afPlicalion fo aback olley comPonenty Toned ot yy B itd bo credle@ new Thanh wth a doth bbler end 4 Dleuy Layer) ‘Tanel Cayoelmonage’ Aeyeel)=> 72 ts wed to create fo ree Pores Mg We wk he sPecthing Layee) menoger Taeely >The o, : Serax seteg thee Lass 44 hey. lyfe of contalrer whith 4 Me Jere .0. ofple, Lay, Ps Avel.y “Quer Guy Tors, Lite We mak, Window where hofes dS works Lite fe maka Wahi Connecky Lenghe , Jrtonghe , rhe are added fo creak oh Path sepoy, eee, o rive hells be qoakity # ke oA client Cha he TOFoleg fred rhein a lop Neve! dow On @. fe taper 0 2p fb Border ancl $8, egus fobe some berm oP ‘rho! bron D The Conbrohe ewer, ? vob 5h seme 7 Saba 9 ohoesn't fave motimiee and merenkee ee coltod, bebong Wodel Teanvas The rtodel ¢ Pr The bonvag hii, Coobsole ond vepreaun's ¢ dhae tedhe Lin Pern OMe Where Ye #Plicabon Can Je Feo ov prov bap ? an a Dhica eh we 7 07 cP Phi Prom Me ren aaa View y : > DFspy CY he coroners yy GY he $1 Pa fayy 9) Lustrate mye ath le doge wy 2 Seren ny Poth Browser | | Conbieber ¢ $b eg cea) Ped Seah Ponte her 4 ri aller, = { And We yb vodel Layer ¥ lak —\ conbroliey Renders vie. haden "A condos tee | L 1 Corbeing Pda bes gor aad dada | > the mu (model - Hew Corbralter) detton Pablerns brenby an a66l? cafe, 0 Ibo Kesee Poy: He model CAL kerdley dil He view (hth 4) whol Wer: tee) and the Confye ley if o yeh connects fhe hoe). These snabes eusler fo 207% on , for seharately Aedtr Beer bveryWing otgenized and frProves Mh — vc quality # Ke shoo P| LA chiee/ (browser) sinda i vegues) jo He tor/reller on Je ever Side, far a Page ghe conltolter, Vhen calls fle model. 71 fen He veg ushy dba b 3 te Corltoller Praniler fle obhd tiered b Ihe foo Fen ihe adel “eardfine Yo Wd die (nde viva cont0ller) dein Poller demons rates Ihe dala and butiren fy ¢ on heabion Viewoy 10, OY Me cle Shaw po mod to the vt0x ond Seods “7 Foley bo he toni lex >t bt bef Hed pep Sadly Inkevad wh ke Hodel PLonh, Mer ache as an Tokrmediary behveen He rodel ee > : t e fo. * Conbabny Laban Jape yee ad aad hy, Prerdborm afin 15/26 ‘5 Explain JScroll Panes and JTree with Example. (i JSerotPane ‘nsScvolPene in Java Sving provides a scroll view of another component Its 2 Ightneight container that autorsucaly manages scral bars (host andor vertical then the conan it cil isnrger than the ibe area of th srall pane, Constructor of SeralPane Constructors ‘Daseiptiene TEs gaa carstuctor tak Tes w rere) ‘mot JScclFare, THiscoraMate ceitesa Kcralbare WEY JSeralPene|Comoorest comp) | specifed vien component asthe scrofable “Tis CoMETUCTOT reales an awy BOIPaPE Sean et et ‘withthe specified vertical and hexizontal herzonta) rh “BaTara| ayaRMETRGR —| THECOTSTETG Ceates a. RODE WANT layout ifeallyouk menace. Methods of JScrofPane ‘Methods Description cq [Sse verocal srolbarooiey eld est-orervatsreisrDoleyine hertzeral) [Sets the horzortal albar ney Java Program to demonstrate simple JscrolPane impart favacening itmport java I public cas Simple ScrolPanaéxarrsie c ese voi insti Frame fame = naw [Fare'Sirle SerolPane Bear; fame =1DefautCloseCpetetion|FramecAT-ON. CLOSE), [Link]/300, 200) MP reate a ered to Fold ast of tte “arel pan = now JParel ‘panel seiLaycus(new BoxLaycutfpand, BoxLayoutY_ AX A Ae lege nuribar of lbels to the pare for(int’ = i <= sori) { Label abel = new JurboltLabel "i and aialabel: 1 AU creates crooner set the poral as fs vpn {SeralFane scrolfane = nev ScrclFane(paret (740 te Jserwane to the rae, [Link]) fromesotvistletru) } b Ovrpas ‘Bi sinpe Soothe: a x ees 2 fee i 1) Stree In va Swing, 2TTee’ refers tothe JTtee component, itch s used to dispiay Hhorschial dats in» graphical zor interface e epresarts data na tree ke suuciule witha root neds, Dances, and lea des, Commonly Used Constructors Constructor Deseription Tree TH SarRIRETE Gates ee witha are mec) Tee is created withesch element of the meciec aay becoving a chid of anew oat rade. Tha constructor STreefObject{} | usetulvhen you want to bulda tree structze based onan valu) ray of valle TieeltresNode root) “Thee is ereated withthe specified TraeNode as te reo Example of Java JTree: Import javecsning” Inport javex swing tre Default reeNocs, public das Dyramictresbsarple [ publ state void mans args) 1 “Pram fare = new Jromet GeakstorGaces - Java JTree Bape A cresting the ro0t pace Defadk Mutable reeNode root= new DefauiurablatreeNodel iat") //Creeting ent neces DefaueursiTechiode paare! now DefaultMtableTiaeNledoParent 1 Defevurablelreenode cnHLI- newDefautMutabletreetiodet Crit |} DefaueMurabisTieeNode o¥H_2- new DefautM rable reeNoced Chil 12 adden chic nodes to the parent) parentlasofenlel parent adoferet 2}, I crating anther set of chock DefeveMutabel eehode parentz haw Gata atatlereNod(‘Darare 2 DefavMutabierieehode cHkZ1 = new DefaltMutablerreeNoce( Chil 2") DefaueturablsreeNode cvii2_2 ew DefaltMutablerreeNoce( Cri 22" (/ aking chi noces 1 ae poresk2 parent? acti? 1s paren acchid2 2 (Adding parent nodes 3 th woot rootaddparert rootaddlparert2h: (creating te sree Siow 160 ~ now Tivoteosh, (Wf sda the Te tothe rae within a serall wesre ‘Temescilinew sserolPane{tiee) setting tarrepropenties fremesetsize(400, 400} framesetDefaultoseOpertierd “[Link]-CLOSE srarnoso\isb [trek ) 1 oureue Brea +e Domere Cam emess ‘6 Explain STabbedPane and JTable with Exernpie FTabbedPane “FlasbedPaneis ¢ GU (Graphical User Intetface) component in the Jove Swings library that allows yeu te create. tabbed pane interface. & abhed pane ica container that can store and organize multipe components into distinct tabs. Itcontains »ealleetion of tabe. When you cli on a tea, only date related to that tab wil be displayed. JTabbedPane comes under the Java Swing packaoe. Constructors used in JTabbedPane ‘Constructor Deseription TT CORERTOEIG ans an empty TaBHEA PANE WITT HO STabbedParel) | tabs ard no inti contere when a TacbedPane is created “The TebbedParefnt taoPlacernent] covetructor laws to creation of a JTebbedPane with a defred inkl cation {forte tabs Th te placement option spesias whethar labhedPane(int | the tzbs appear at the top, bottom ket right of the tabplacerent) tabbod pare Methods of the JTaboedPane | 1 Method Description ‘BAGTAETSrna ila, Component | Cresiars raw tab with the Guen tle and ‘component content TamovaTabstlint index) TRETROES TE fab at the SUE IOL Teta fe number of tbe resent Fe getiabcount) Tabuecane. Progrars to implerrentSTabbedPane (iara rogram rocerenstri= ((srabbectore with tabste Import javaswing+ import jaa public ass TabedUBcarro ul ste voed manistnneg) as) { pubis yoda 1 Createa new Fame (windows “Frame window ~ new Framer sTesbecPane Beero, 4 Close operaton vane the Wincow'sciosee Winelou o:DafatltClossOparstiony ame EXT_CN_CL OSE); / clase ciation when the inn isctced 1 Si the eal sie cf the window ‘window se:5ze(400, 300}; BBL Stein rence ‘window se'Si0(400, 200); crea HabbedPares which wil hold the tae “TabbecPene tabParel = new rabbedFane)): A create the fst tb (pagel and oct ko rt ‘Panel page= new Panel Dagelaciiinow Label Tele Tab 1) the second tab (rage?) ancadka abe tot ‘Paral page? ~ neve JPanel ageZaddinew JLabell Ths is Tab 2": (create the thi tao loages) and aoc. sabe tof Ad eho threo 308 tthe Tabane tbiDanoladTeb"Tab 7, pags {bereledTeb'Tab 2, paged): tabPareladc Teb|"lab 3, p30e3): (/acetthe sabbaceane 10 the serere's content ‘wewiow adtasPareh (/ Make the JFiame visibe wendonset\fasaltral vse (Craba | tana JTable “Tables a component in ava Swng used to spley two-cimerlonal daca a {bul format. simile to a soreashee.t aranges cata inrows and columns ne roses farctienaties Ike sorting, seection of cal endarng ard acting. CConstructersin JTable |. STable(:4 table is created with empty cals. 2. ‘Tabllintrows, int colt);Creatse 2 table of cizaraws* cole ‘Methods In JTable 1. ldColurn(TaslaCaluren flecturn zed: 3 ecluren at the ond af the sTatte 2 dearSelection : Selects al the selected rows end colurmne 3. ek CalALin: rows int co): ects Ue intersecting ol OF the colurrn umber eat and row nore ro procyarrmaticaly 4. setvaluest(Object value int rovy, ne co): Sets the cll vale a {or the position raw, ec in the able ue Programs to implement JTable Import javax-swing. IFrame: Import [Link]; import [Link]; publicciass JTableExamples { JFrame f JTable | TableExamplesi) t 1) Frame inttalizetion new IFrame(): Ij Frame Title {setritle("JTabie Exarnple’) // Data tobe displayed in the JTable StringllD dst {"Kundian Kumer Jha, "4030", (Anand Jha! "2014", 7") J). Cournn Narres String] columnNames "Narn", ‘Roll Number, "Department! J Hinitieizing the JTable |) = new JTable(data, columnNames); {jsetBounds|30, 40, 200, 200); deciding i 10 sSeroiPare “serallPane ep = new JScrolParel tadaispl; [Frame Size FsetSize(500, 200); 1) Frame Visible = true FsetVisible(true): ) ‘public static vard main(strinaf] aras| i naw STableexamples() (1 4. Explain JCheckBox and JRadioButton with program “re Ichacldexclne Ie uoed to ereate a checkbox. tleured 10 tan an option cn [tve] or of (ac). clcking one Checkton changes estate from of to “aff or thom “eff to ‘on “It hes ogaksution dass ‘Commonly used Constructors: constructor Lichecktoxd [Description \Geates en aly unselected check box button wth na text ro ieon reneosurast (Gesasa Fila aCe Te bo tai eet Licheckoxstina text, booken sdected ‘Commonly used Methods: Methods vole sertexcstIeg 9 (Greatee a cheek Ban vith tact al SoSSTIRS lnhetne oF note ical selected Doser tis used roset specified text 0 the Icneckon, Java JCheckBox Exemple Import javaconing” ube dass CheckBoreame C Checkaexbaampal) t Sea oaTERT Reed emiteter “Frame fe naw JFremet"Checkéox Exar ScheckBln chechBont = now Oreck Bon, check settourds 100,50, 80,50) “chechex checklona = new lehackoe' J" hh checkBo12Se:Bo4ras(10000, 50,50), ‘asclecheckBooth tadelehecktoxak {setsleiao0,co0}, fsettayoun(nul) cenit 1 ible ttle volt msingstng arg) i ‘re Checkeontxarik } cunt JRadioButton cption rom multe options. ‘Commonly used Constructors: onstrate esietion aaa Ceatee se unsactadrads aaenea [creates an oradlected ado button with soeatted tee. ereatee avacko Buttan wh the weaCT |jesalnBurton(sirna s boolean selected) | Tmates rato outtonv/ BR eearerTaT tis ceed to sat epactiedtaat cn baRIon Stina aerrexet Ipused to retumnthe text [ofthe utson. Java JRadioButton Example impeet vexing: (ble dae Racin dition rete | sramef aslesuttonésempen( “RecioBuston rere sadicButsan'A| Me, “acioBetone2=rew JaadloBurces) Female AzetBounds(75)00:100-30} ‘Pesetouras(7550100 30) Burtonsrouo bg-new Buttons gad baad; Tada a2) t5etS2e1200.300), feotlayoutiulh: Teetvsiket}: } publi statis vid rain(steal rae) [ nen tacuLrsarexampe) import java-aut+ 4; public class Simple —caleulakoy extends Sf Frame | im plement At iste jf tent Biel dis play ¢ double numa = 0 Numa=o0 , result = 0 4 w " t _ | add (display » Border layouk 4 Noe TH) 5 A_pan. = ees Tpaned Done = i eee ___| _U Button Label String LT buttons =f ope gh kanye Et, wg" mgm, wae phy tat ug wd Wg wet Me tye bi WAd4 buttons tv _pane for (String Labi t buttons) { Button btn = new JButton(tabel ) 5 Er ne “Aviat " : _btn-add ActionListener Cthis) panel-add (btn); | ip Cnput. matches (" fo-aJ")) f q a t Text (display + get Text + input); | fete conpud mate YT empulamatca (Meek 8/2) | -try { - is: . 3 | ——|_0perator = Input 5 | display. set Tent" "D5 display. et Tent C"Evvar "Ys é tov) case Nt" t- yecuit = numi+tnuma: break: Co =" *~ yesult = numsnuma: break: case N¥"- yecult = numi * numa + brea le 5 Case Vy ns I} Chum2 == 0) { display. set Text (“Cannot divid by Zero "Jj return 5 ; Yesull = fun) fn m2 ce bye a —l } ae | display se Text (String volue f Cresult)) 4 display + Set Text ("Error ")} iS ho be ¢€ ; inp Q cu" " ){ display. Set Tent (" "Di Operator =“ "j } ——{-pub X x ic in (Styviy vas new Simple caleulabor C14 } t

You might also like