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

Java Complete

The document outlines the development of an analog clock and a scientific calculator using Java applets and Swing. It includes code snippets for both applications, detailing the graphical user interface and event handling mechanisms. Additionally, it discusses the use of MVC architecture and Swing components for building user-friendly applications.

Uploaded by

hicomo9645
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)
7 views

Java Complete

The document outlines the development of an analog clock and a scientific calculator using Java applets and Swing. It includes code snippets for both applications, detailing the graphical user interface and event handling mechanisms. Additionally, it discusses the use of MVC architecture and Swing components for building user-friendly applications.

Uploaded by

hicomo9645
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
You are on page 1/ 21
P i ail Jre22 EXPERIMEN | <6 - At + Dewahp 07 orgloy flu using opp? eyrhad dee dr guns Ait dye sn pes wg pape 2, un HN Webpogs ne gpnancte dy rome Cone Gand Hy teewie ond wala ar cin Lide % AMuentaga oy Lppiv Seg gy Epp Ihyy ou fticust # Tho asu rrany covawe-ga 0} Opto © dt woos ot ‘clitnt Aids So fos sexsporus Hr8 « Sewud under ory propor ) ede con As executed by Recon ae Jndudivey Linu» Wdinelows y Mac. Os %€ + Deewhour oy Peper. © Pugin ai Stequieack ob bine + Lyecyee oy 12) { hour -= 12; } gsetColor(Color.white); gfillOval(300, 100, 200, 200); g.setColor(Color.black); g.drawString("12", 390, 120); g.drawString("9", 310, 200); g.drawString("6", 400, 290); g.drawString("3", 480, 200); double angle; intx, ¥5 angle = Math.toRadians((15 - second) * 6); int)(Math.cos(angle) * 100); y= (int)(Math sin(angle) * 100); gsetColor(Color.red); g.drawLine(400, 200, 400 + x, 200- y); angle = Math.toRadians((15 - minute) * 6); x = (int)(Math.cos(angle) * 80); y= (int)(Math.sin(angle) * 80); g.setColor(Color.blue), IEEE ' "Oo a B-drawLine(400, 200, 400 + x, 200-y); angle = Math.toRagians((15 - (hour * 5) * 6); x= (int)(Math.cos(angle) * 50); ¥ = (int)(Math.sin(angle) * 50) 8-SetColor(Color.black); B-drawLine(400, 200, 400 + x, 200- yj; }} Output : EE —— VIVA Vor & thr wv Pople ? w& A favo Appr a os poregocrn Hal Com Ju Pgs Gnd be recused in pon er Osu Lad fan Lsuotirg cy rama Grd Jnverout aes Os Exptein th bby gyeu gon Apple AS An oppler may undinge We paw Nek D brik t An appr ip initeberct each iw 4 Soadse. Q@ Slav: Begun HN execution gy ar opnte”- @ Step + Slap tn execution ay An appur @. ~Desrey + Pozpom a fire exivens of 0 -fova Visdued Modir feovrnmay, a chun OnpUcesion Suquiscer cr rnalvy wir c mutyd Wi Apeufuc Aigotu, Ir Gndin te Serr Us CxeCUHOn a 4 n ee Appl cbo’t Turd Aush co munsd te Mow Hrun Cxeccsion Ft fiver Gpptes +ypicaly toe 0 Suvomtion Seunty PAUyy USL feurey J Cpplcctions taveuiy 414 rary Sutoxed Aeewty pots CC ?_ LL EXPERIMENT F niaare* AiM 7 Dewwlap an avadog clacke Scienvipe Caludeseur arg Swings, ibsony ond on Theory +. Swing 4 a java Leurckvion Claosin Cyr) Cxlervion oy thy Abvraur Window aie wel ed te Arwen = if (1s1.equals("")) s2=52+5; else 50=50+5) [setText(s0 +1 + 52); } ed(ActionEvent e) command(); “ng see ea «charAt(0) <='9") || s.charAt(0) =="'){ CEE 3S: else if (s.charAt(0) == 'c' { SO =s1=52 =", | setText(s0 + s1 + 52) ; ; else if (s.charat(0) double te; if (s1.equais("+")) te= (Double. ParseDouble(s0) + Double.parseDouble(s2)); else if (s1.equals(".")) te = (Double.parseDouble(so) - Double.parseDouble(s2)); else if (s1.equals("/")) 7 = (Double.parseDouble(s0) / Double,parseDouble(s2)); else te = (Double.parseDouble(s0) * Double,parseDouble(s2)); lsetText(s0 +51 +52+"="+te); 3 else { if (s1.equals("") || s2.equals("")) si= else { double te; if (s1.equals("+")) te = (Double.parseDouble(s0) + Double.parseDouble(s2)); else if (s1.equals("-")) te = (Double.parseDouble(s0) - Double.parseDouble(s2)); else if (s1.equals("/")) te = (Double.parseDouble(s0) / Double.parseDouble(s2)); else te = (Double.parseDouble(s0) * Double.parseDouble(s2)); s0 = Double.toString(t); sl=s; LsetText(s0 + s1 +52); } } } Output : 0 ————E ll \/tva Voce g rig Jun Sing? oe os A aw couty” a type oy Tees uhich a OO ae Ft ss OW paw y th Ero feunce! Indu graphiced er snvegous (C4) widges Suh Jex-+ POKEL, Diten ) Apr fonn, Ord table ve TFC ord per Dua Fourclation Kosa, Th SEC On & Sab of Fava 2 Photforn 4 NJaver low _Llosierdey Provided % Por of Atendene Edvion (Tese) 40 appar -baudivg Ue Jnteyou Onc goaphuy furiortiry fo? Lune appycotions Hot LoL gun on Papulen playparms Jun oy Muvorg juiedeass, Liew, Moye OSy. 03 Wer u Awr? As Awd oi basicosty tony fan Crohly puggrornmen 3 clundep Comporvnr, Hunn C4 Luindows, swyonnhe far dromaliing fry Pwr Coun sno the onprop do AY bos Gporotig Ayton. they ua 4h Cbfporne blw AWT one Goings? ce Aw 4 Arovy ~ weight Comparer y pub Stairga 3 Lgnr- weg Comportna - » Pwr » OS chipendew Aucawe i dae roti Grnports Bur Sion ry Compo OM OS Indepdit, Abxsot Window Toolut AWT Java oppucetion, voith oUt ond butow. Th JVM 4 pe Couls ve i r EXPCRIME N18 TM 3 AIM e Couete an edtan dua MS- Wand Aaaing Awnings TERY + Son a wee wh ighweignt Gu] 4c Sr 0 guide , ae i, oy cordgon dan athag oprrvar wire 1g] Nov 2022 . i . sg may Panay onc may furibu tran Aut, te Snir ya ae Unihowrare Swings Favour MYC * TW MYC Comion 7 Sn genres, a virues Compan” 8 6 Compante cy Hout Cline Cxpenrs: 1+ TH Woy Har Hy Crpovnla 2 TN Woy Auch Har Hw ComporertA Be Th Neale Jnprroton AmMoickd Wim Hu Gmporsrss, « Ow the youn, Oru Comporen- ances Jos proun Usuy te he Ex Cepttoroly epesiod i= Med — View - Corvzetun coy MUC fon Aber fo Jn MVC demvategy » Hy trad) Cavuaporda to ty Alte inp! Cwauckd with hs Comper OTH View determin tou Pv Gmpern JA oluoyrd or dv Gourn , Arvauding Avy Anpects of Hy Ure Har ant CYpeurrd Ny As Luonel Mate oy de wrod | o The Contraun olterriny tow We Comper Sua te Hy Dorks tehin Sundind om Wh Moun, toa do Hs Ln, ow. ™port jay; "Port javax.s MPort java.io « awe wing.* A.awtevent.+ IMPort javax swin, Import. Javax, Class Editor e, JTextArea t JFrame f, Editor() { 'g.plaf_metal.* Swing.text.* “tends JFrame implements ActionListener { f= new JFrame("editor" i try{ piManager.setLookAndee!("javax.swing plaf metal MetalLookAndFeel”); MetallockAndFeel setCurrentTheme(new OceanTheme()); catch (Exception e) { } t= new JTextArea(); JMenuBar mb = new JMenuBar(); JMenu mi = new JMenu("File"); JMenultem mi1 = new JMMienultem("New"); JMenuitem mi2 = new JMenultem("Open"); JMenultem mi3 = new JMenultem("Save"); JMenultem mi9 = new JMenultem("Print"); mi1.addActionListener(this); mi2.addActionListener(this); mi.addActionListener(this); mi9.addActionlistenerthis); m1.add(mi2); m1.ada(mi2); m1.add(mi3); m1.add(mi9); JMenu m2 = new JMenu("Edit"); JMenultem mid = new JMicnultem("cut"); JMenultem mi5 = new JMenultem("copy"); JMenultem mi6 = new JMenultern("paste"); mid.aduActionListener(this); 5.addActionListener(this); mi6.addActionListener(this); m2.add(mi4); m2.add(mi5); m2.add(mi6) JMenultem me = new JMcnultem(“close"); mc.addActionListener(this); mb.add(m1); mb.add(m2); ‘(Action vent e) String s = e SetActionCommand(); (Sequas( cut) teut(); } lee (sequals(copy')) { Leopy(); } else if (Sequals"paste))( taste); se if (.equals('Save")){ HFileChooser j= new JFileChooser("f:") intr =jshowSaveDialog(nul) if (r FileChooser.APPROVE_OPTION) { File 'ew File(.getSelectedFile() getAbsolutePath()); try( FileWriter wr = new FleWiriterf false); BufferedWriterw = new BufferedWiriter(w1); wawrite(t. gettext); waflush(); w.close(); } catch (Exception. evt) { Option ane showMessageDialog(, evt, -getMessage()); } } else JOptionPane.showMessageDialoy operation"); } else if (s, -€quals("Print")) { ty{ Cprint(); } ‘atch (Exception evt) ( JOptionPane.showMessageDialog(,evt, etMessage()); } } elseif (.equals("Open")) ( Hllechooserj =new Flechooser") ‘showOpenDialop(null) elf, "the user cancelled the SE 4 String String 5) \ FleReadr ent = ROW Files uttered, Header(h nate B= new tutte eader(tr St br readtin tferedReadertr) While T-readdine(}) t= nul { slog, \ os ) tsetToxts, atch (Esco JOptionrane ShowMessageDialog(f, evt.getMessage)); else " celled the ‘Optionvane showMessijebialol, "the usr cane Operation"); else i (s.equals(*New")) { tsetText(); else if (s.equals("close")) { fsetVisibletfalse}; } Public static void main(String argsl]) { Editor e = new Editor(); } y Output : ‘a gio mE sey enaenaeie mr . cole eee ————————_—— \/ivin Voce CO, = Coy ane Arey Laseighy Ga aucucsed win He A sa A hoowy cues nw Componn # ee wosty Know FD HES Quon trapw Atrun guscwr ushich Yer Peer oho bgarweipe Comporss A Lignicoeigns Comporw 4 se ray AN down Swann ef or Antoter, vehi: te Toh surouw oy sh Own - 40 a Jigrker . Re (hor ai on wn Jn Swings? Eww Doxicaly os Chastgug tN Ae | ON bee cela He (tld an ewne g Lohr a an eww hendlen Jn Busing? Euanr Shenoy uy Danicaly Oo Pawoy & Compwor (ncgan uate 40 4 HY Program tow fe av Susporw JO GQ Apeugt ewe | \ ke Aldus |2022 CXPERIMENT 4 Ain. fe — |" dtole ma & Ayub for Us Coole so Mew tt ures 4 * dur rows ylaed yor Now Woe; t out Apa a Hy Pogom hoy sunk On web yh brow! * Seau, ee midds Slayer bho o aiquo um Ind etebout Fgpucetion Om unr on OD Th ns! Kons estay smint A” Pot Nef © 9th ‘Aird thy Saquay 40 Hs Loeb Q Woh Arwr Steer Hu equa | TAI bye Aum pom HN Suguents po ty Caro Sanus Q Aunulr eanas ty Sau and genuncda Hu Buyponu 20 NM sham 0 ofp. Qh Sms rd He spo Je i bow 4o thy eLhunk and @ Thy yun Anus sands A spon ANE Chunk browwr oliplys O° a Jouen . Neontga ay Anais Our OS @) Beret Rejeomana (ii) Soul ex cass within act Apau O} Jown (iii) Ploeg ‘mn ~ Jnolaperdler- Civ) Meow Benet (U) Communicel tyiin Ol Aoplcction itn PME. Ry Aim: 7 * Create a seryt a Servlet that uses Cooki Visited your servlet Mahle to store the number of times a user has Java Code import java.io.* impor j RAN. servlet® import jay Public av.servlethttp.t; lass count extends HttpServlet static int count=0, c2=0; Public void doGei(HupServletRequest request, HtpServitResponse response) throws ' ServletException, IOException ‘sponse.setContentType("texthtml"): PrintWriter out = response. getWriter); String name=request.getParameter("tI"); Cookie cl=new Cookie("count" String.valueOf{count)) Integer parselnt(cl.getValue()); out printin("Weleome=" count++; else 1 cl=new Cookie(“count" String.valueOf{count)): count =" etry cout.printin("Weleome="+name#"\"=count): HTML
‘submit" > Welcome Thor Viva Voce Os Hews TON lOc oy cg Usssday=l gaa Fi Ay Only ore Oheo ot ti dims op fir suequar by 40M QOH Lueh Conouney, bz het» Wy tye Gee gf 0 Somes? Aw Senter i Dooclict D Sout 8 Indeniedig @ Seu 3s Jnviodnd @ Cem HN Suro © Jouw w levees OS Oh A tiger saose HV orjer of sear? A» TN Web (onesnm an Aerudu- Coredvun, OS Uskn Aude abjer ai coucted? Ay At Hire oy Frar sequar. 9 Indexpour ¢ who 2 TH RequarDuypoten Invedout be Wel) Kemah JAP oo Buguar Je Oral Suse a ja ConJenr a Overien ¢ “Tn Jnlouuplan Con Alig hy tui 7 SEU { ‘Ss \ 0 SO ee-||tCS a IG fLx<120?* EXPER MENT + lo Alm Coes a Simple joua hoan houing hound ond Consroanndt poicpentics ua) Theeey x A SouBean 8 Dove ou Har Aroskt foie following Conmntions . | : 4s Shotd pour oO V0 arg Connouuteny of wo be Soule © Ie Shull provide mertods to Av Onc Ge (Spories rouny cy getter One! Avtn mun He vou af tH hy wot Sue Bron. 7 Attcrcing to Joyer while papery ar 3 Seusen Ae Or A bean enceprlaror ray Gia 30 Ort cungecs S Can Que Hy alyes Grom prep four losxtouws eoy moinkeinit « Jove bean Peopenties ; aude A ceveheon proputy ™ 2 suad pwc, Svar Orly a oy An Towahion feeders ony OMe direugn Fuse Wasrads 4 Tove: hoon's implmonetion ow, c ~ @. ger Pew ee Property Terme wu Fors thee cP yrOstet Anu ; : The amitrect Laowd Je urFowtNowu C) te swed hot re matiod i Courd thy Atauan. \ @ grPopoyomO: farevompu, if te Propety rome Fivrrlne y dna ram wows be Atk fbotNawu() 20 Wau Hod” propoty - TNS molvoct 4b Contes cod amilelees, nent:-1O Java Benas Public class Employee implements java.io Serializable} private int id; private Sting name: public Employee){} public void setldcint id) {this.id=id;} public int yetld()freturn id} public void setName(String name) {this.name=name:} spublic String getName {return names} 1/ Calling Beans package mypack: public class Test public static void main(String args{)){ Employee e=1 e,setName("Thor"): System.out printin(e.ge ew Employee(): stName()): eveeecee eee OUTPUT Thor OE . - ee VIVA Voce & y Coher & @ wo Goons? te AS A To bron aio Bogs Cveporuntt bros fos PO - +o be Su -—wobl jn oO Uonioy Y hye Co ot ORd WNch Con bo Liuetly moripnore jn +N 2 Whar aw 9 K the Ciclue, Jexa beons : ; By parse, prep Faoue Gnd Manda pr "Wat Onl a Dyn Jun © Boon’s rapes, usted, and a Gerizuud & Cxpomd fo an “appuicetion bude foot - Os aa ty obgjen prepovia ayo Jowe bean 2 _ Simp » Bocdean Propoty « Indexed Prapery e Pound propsy © Cnvsaind propoty. C24 bow w a Jan Aur wwexd ? z Us tv fatlowing Commerc’ Jo Cuose a Jan fur ash ee ee & \

You might also like