From ef2390711b208628a1d620bf5994d55dfce0bedc Mon Sep 17 00:00:00 2001 From: mohit17067 Date: Wed, 3 Oct 2018 21:38:32 +0530 Subject: [PATCH] Add a calculator using swing API - java. --- GUI_calculator/mohit17067/README.md | 8 +++ GUI_calculator/mohit17067/bin/CalcFrame.class | Bin 0 -> 2053 bytes .../mohit17067/bin/NumberPanel$1.class | Bin 0 -> 1131 bytes .../mohit17067/bin/NumberPanel.class | Bin 0 -> 1148 bytes .../mohit17067/bin/OperationPanel$1.class | Bin 0 -> 1275 bytes .../mohit17067/bin/OperationPanel.class | Bin 0 -> 1296 bytes GUI_calculator/mohit17067/src/CalcFrame.class | Bin 0 -> 1809 bytes GUI_calculator/mohit17067/src/CalcFrame.java | 68 ++++++++++++++++++ .../mohit17067/src/LoginFrame.class | Bin 0 -> 1974 bytes GUI_calculator/mohit17067/src/LoginFrame.java | 64 +++++++++++++++++ .../mohit17067/src/NumberPanel$1.class | Bin 0 -> 918 bytes .../mohit17067/src/NumberPanel.class | Bin 0 -> 991 bytes .../mohit17067/src/NumberPanel.java | 33 +++++++++ .../mohit17067/src/OperationPanel$1.class | Bin 0 -> 1051 bytes .../mohit17067/src/OperationPanel.class | Bin 0 -> 1117 bytes .../mohit17067/src/OperationPanel.java | 44 ++++++++++++ 16 files changed, 217 insertions(+) create mode 100644 GUI_calculator/mohit17067/README.md create mode 100644 GUI_calculator/mohit17067/bin/CalcFrame.class create mode 100644 GUI_calculator/mohit17067/bin/NumberPanel$1.class create mode 100644 GUI_calculator/mohit17067/bin/NumberPanel.class create mode 100644 GUI_calculator/mohit17067/bin/OperationPanel$1.class create mode 100644 GUI_calculator/mohit17067/bin/OperationPanel.class create mode 100644 GUI_calculator/mohit17067/src/CalcFrame.class create mode 100644 GUI_calculator/mohit17067/src/CalcFrame.java create mode 100644 GUI_calculator/mohit17067/src/LoginFrame.class create mode 100644 GUI_calculator/mohit17067/src/LoginFrame.java create mode 100644 GUI_calculator/mohit17067/src/NumberPanel$1.class create mode 100644 GUI_calculator/mohit17067/src/NumberPanel.class create mode 100644 GUI_calculator/mohit17067/src/NumberPanel.java create mode 100644 GUI_calculator/mohit17067/src/OperationPanel$1.class create mode 100644 GUI_calculator/mohit17067/src/OperationPanel.class create mode 100644 GUI_calculator/mohit17067/src/OperationPanel.java diff --git a/GUI_calculator/mohit17067/README.md b/GUI_calculator/mohit17067/README.md new file mode 100644 index 0000000..eb08d1d --- /dev/null +++ b/GUI_calculator/mohit17067/README.md @@ -0,0 +1,8 @@ +# Calc +A simple calculator app in Java, for CSE201 refresher module. + +### Instructions to run: +* Simply 'Run' if using Eclipse. You can change the main class in the run configuration. +* Compile using `javac *.java` from terminal, and run using `java LoginFrame`. + +**Update**: I have added a login page as an example of how to use JTextField effectively. diff --git a/GUI_calculator/mohit17067/bin/CalcFrame.class b/GUI_calculator/mohit17067/bin/CalcFrame.class new file mode 100644 index 0000000000000000000000000000000000000000..2a2fc814f5f3d554b6d32373e6e1de687d542f8d GIT binary patch literal 2053 zcmZux+fv(B6kP|5WfTGC8WM6LB%#Iz%q`?XZeSpom?SL}N}8q-wgL)5a%DL{`qH;d z-tqx`$n+(BY&)&#l$m}&KdS9Il5k9$@r-=VKKrb__gZ_OzyAK?PXH76RzaOWV@9{~ z^RB*QD2NEOz0hCkd+E}yX>X<%eY=3_8l|%3O}mCJ(3v~tGE??E$DR_1-ZX8~yDdT(gkV_noq*q5~&os1^x#O2cXNusXs8=K?(m zKXdTeDTWT(u4{V6 ztXV2r`o7e1O~V(mo#ZgA7<(R@#n>xy&`N%@w*|7)HW|Zn01F`oVx>eRaW3C!PGP0rJOFU6gz;gvGJ?^(;4V;EeY;m;nTe>^V6y*q#%NMW| zY#;NVb;@K*!wxv9G0zDGLr%-=N3#?tYWQ3d5Dgv|0YR~2jz8~?%WdXpYZpejrLw`P zU63QN>~R2=^kOKGy6lwQyfJS|37e}8Gb}5@1=d>6H&38WPAFFquK6nQ+emXi*Yfuu)_(EA%MCV$1n`U)<~|6edrK{_dy z6^yUR|3h3|kE_A&0M{$Hd5F8~j4+c+{qJlpnUePou^>Gbmj*xLG3X;lD!BhMbFISz ze&^B3ZxicjmTxQC5l1gy(jl&{@I}0XE-c_Ap5hdxJdIcA!FM=|H#mpyaUMUAoA>C$ zL!$Hs9N-Z?v8n&dNm4@^?sPc;S zI-5-V4zmJBR$N~r!w{Qmm|3JL#R!QSW!7U{jq^8w8x&+3lbGeZc^}tE?sd|6gA7a| z&nI)6Vo4cp`weP^H8xO)fGtiazJW_tnki=q9!2k_FlD@C+&(N~m#ZlDh|z_}KMWdG VAQTkpg&>9TcoW&%=V={Y{R_%HwSWKs literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/bin/NumberPanel$1.class b/GUI_calculator/mohit17067/bin/NumberPanel$1.class new file mode 100644 index 0000000000000000000000000000000000000000..dbc240e85b318aadcfac197181b204284212c310 GIT binary patch literal 1131 zcmaJ={ZG?S6g_X7E0n^@JLjHz?)&xo`%eH%s3}M>^nPr&_Jz009bp$16=WFnV}8oZ zHg^uoJNw7N3>0J;#>2n-EGUap;RNM%Gq7BzZux<5gvXE#jx4{hK#27OWQ9RF<#xeo zw-{KB!d5KD3RW5VjT>>bVuK-5b(^9a3^@%7y5y{1LpM|vY24M&g8_!LAwzR@%MlUL zC%$hBhJ4*Mx!vHNCD-xKjLb?#Cvqw*QdT)0=D#bv1J`SbCc}hLzg6Ovlv^n_RE*() zf^mkP1ek^iOfqzF(-eNFfAprXV!g_3bKB!BQBm-aVfebddx2*;hZ}9nZVFFD0n-W| zGjv~_(C`EX5qg3*H!c6f=3f{FjAE2&XihIKt~7IwzS7t^^wI_LU&Fvb`erE*7{m~LNC|;mUYyA>WJ9yQ>N(Zag9BO!W1T%yvd4?jamrT^P7=FI3P$&fkh;o!OZbca=o*1Ao#mo$&VrK9U`6vxmM@!lc^uIUaFaK(y zU?lMZyZ~>&`w*Y6TX1NT@ARIZ=Y9L*_qXo==CGoq@$)H=e ziSxK1&>T8Z)l#58T|A9Ym90rn?l?g%Q_|5}OK=Knr4mKHXP_U0ItBzfV&}3X_Ntag(+&~_V%(JxxQC)!^rWRKwz{EtFzCpWY1a64=hFtKg*Sc%N1SAYc|eQk*Z#FmytUkccGz6@i2rRNfN2 z>uBQM%-1j88+bmoj$l|*U(jkDqkW^XF=eETBXk_%oVNG@*1*y+dNu~XqVEX9^IETV zjIj-C@CXx!NL#(yAud0Emk3bwF?dkZv}%-M!Mq%ed|*49N` zHx@8}JY_{npI{i*X+2l13O8_*FV=@!tX|M^2DdR!6eAc#j<;kj#v> z_yhb=j(6LLlsdMPZ1&!}C+FOI^7GfX9{?U=&ph`hDa^SkKL3w5|*1<)aALnQFetT9ELV`-zZ1ZbUfdPnxWhgH=}lm zA)Nn^9Mi~NJ*G0M3vq+Qjcs|QbeZ}F2BBLUTaRp-x z?N>n!6H;YZP-`pP6}e9(hrnng0mMmtHvcYwBm?B(DGk#|F=)q*;fiIWTr&A*hF(uc zZPea4;spgW4E;Cfv{W(7qHrYILyZjdn4!ZFym$rH6N@)bOT|;nDtOjls`{HWJO_1G zk^IHRF2neBHg)4={t21Jyqs}LMH(+Oyu>1Th?h#jqS;JcNBN_viI}H`I-5pT!?KhU zaP4|M&5nFB_`ex5bZ)s^|G36Wo`cjayW;3##gHEBZk+eDY$h2gXX&P0CeyD8ci%2b z5qUC4?AoZMXSG#}zNoCp%Vkl<2)WxwS1VdVA!&CY6qaVE@3@7o4rr9^q^DWh`)Ca& zlIQ43Or9f@xIp+zt+1EwZBz*KqmSn(u6VO|%(UVGL IQYZa>1M;CNJ^%m! literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/bin/OperationPanel.class b/GUI_calculator/mohit17067/bin/OperationPanel.class new file mode 100644 index 0000000000000000000000000000000000000000..a41566092d84cda33d408b15d72980a3119f4b4c GIT binary patch literal 1296 zcmZWoQB%}b6#njRb`#csOORSBlxneNgSeGqTLo-!6^jjEO=p?356(4YY;;L>lC08) z_Njlwr@po`6=url59nL}Q0;fKj4qI!+>?9mJ>NOsch3Iv-`}qREWp!I5*XR+hN;Y> zB)%`>u%km0u%5_ga<`d1kK)J8dxf9QpqHj$oIea?CwQ3UG7kk#xh?KiQ@Il^3RDte zWddVAx(cD$k&O59lrTK4E=6&a-(*UAAga+8&|1lMSVI}ZCWbH~P_`Rw9d&{FaU27d zfS5IKhGx#ddo;TS-lu6A_<&~Fz$6h`?t>u+d}u<4q2nV~Rba{IdGl@>ZM*X4q?gw) zjSDL2#{#;&#;4J)G3=s=PjE?KC=2ucO@VWEpOr%B`_^SFABX8;qpeakOjJSZj|L=9Hs&n28e{u*wW_F8|0%jxNhPG*taqv1e}4OR^c`-l?qR{1(Dv}<)^8;- zscyc0@#bHLo~1uoK^b3jorlSF7#gda#R!&A#|mp-#Tl$)99uYx5SP%QZZo#;iuZo8euoFNO5G+cpZ@`FCmyl@ literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/src/CalcFrame.class b/GUI_calculator/mohit17067/src/CalcFrame.class new file mode 100644 index 0000000000000000000000000000000000000000..352ad759208ef8e4bea85e5ac5d2705e2246a32b GIT binary patch literal 1809 zcmZuyT~iZR7=8{US+ZYO4(i5EMlVRtpJeG^i~U8l|mEvWC^oZo1hBc-1?n zcl`mqaC&1e+fExgWu`x%*Zn*@+){B{ zGIRYB= z$=sQ5c%Ea=3Pi4(w&~pvXitu=3WTyw*%0U|n6`1RQQa`y6@9~^MB8#r&&Zkenx*eB zT+)x1v2;dT_FM*?mHwSfRz9%mOO75l6X-FX>sCYejD_tQ&saAdTOhXV>7{2&dd*MB zDio~nJXPJKav=HWcp#ZiU3MC7$yhYy8RJ>qDlNKt)tHdQYIq+XX!sno>p4=rZ=+!i zUkLO{O-A4HGPhi_T+nx%h9^B&H5Bo%rGE=I0Z5aihWBtz!y~LK_)^1H_*%nbF!2UT z0z-#$Za8k)a5D?lnzu9W(=tL?gMlZ6Ex`JLZX1@AR}^frp8GY!)jh(~QkYoR@Kok~ zhLna;qzIA*3snWS1_w0_A0jCbJwQSr;TL$QQ36Wc@RrRNge;uQ=OvCODajd6bk0lG za_YuGX0{;dTSRFQpd&EY>b^uRkS*!9UNKyM22@%u*m7*j()*!|A3s1j>sXG<#A~= za%C|=7ucpC#D0rgjS94WJ@I7W08U?UbeR0!a1t4E)vTNTZIJ-47~39mR`#h#X;XLS zD3X9?kMt$yG<>%X&k635ykNO^+#Sx_Fy9$KpiRymsW55IIoI=248_;~l-h+zb&IiX z@qH6*sYnx{)E>gcNN5*i6fzyfp6D*r-_e=+4V~>xXmbA*u_odvNjA~7CigugiU~FN zcG2BL&mMY<%+OazAJg@x($a4a1JdHe(%3sJ#{9^kCQkn1*K&dDBD%T85JH?^7oWZa zM$m(CQdiK&mvVqF;R#-{Q>frHUSJU4;w-+y5Pl#kKN64EL`29N5THRs+V}xcSp|=E z>PT-?P-;cW=#31ODT7yV;h`X4O} BfEWM( literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/src/CalcFrame.java b/GUI_calculator/mohit17067/src/CalcFrame.java new file mode 100644 index 0000000..feb5525 --- /dev/null +++ b/GUI_calculator/mohit17067/src/CalcFrame.java @@ -0,0 +1,68 @@ +import java.awt.Color; +import java.awt.GridLayout; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +public class CalcFrame extends JFrame { + + private JButton resultArea; + + public CalcFrame() { + setSize(300, 400); + setDefaultCloseOperation (EXIT_ON_CLOSE); + setLayout (new GridLayout(3, 1)); + + resultArea = new JButton (""); + resultArea.setEnabled(false); + resultArea.setBackground(Color.WHITE); + + add (resultArea); + resultArea.setBorder(new EmptyBorder(10, 10, 10, 10)); + + JPanel numPanel = new NumberPanel(this); + numPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); + add (numPanel); + + JPanel opPanel = new OperationPanel(this); + opPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); + add (opPanel); + + setVisible(true); + } + + public void writeDisplay (String expression) { + resultArea.setText(expression); + } + + public String readDisplay () { + return resultArea.getText(); + } + + public void evaluateExpression () { + String expression = readDisplay(); + double result = 0; + char operator = expression.charAt(1); + int operand1 = expression.charAt(0) - '0', operand2 = expression.charAt(2) - '0'; + if (operator == '+') { + result = operand1 + operand2; + } + else if (operator == '-') { + result = operand1 - operand2; + } + else if (operator == 'x') { + result = operand1 * operand2; + } + else if (operator == '/') { + result = operand1 / operand2; + } + + writeDisplay(Double.toString(result)); + } + + //public static void main(String[] args) { + // JFrame calcFrame = new CalcFrame(); + //} +} diff --git a/GUI_calculator/mohit17067/src/LoginFrame.class b/GUI_calculator/mohit17067/src/LoginFrame.class new file mode 100644 index 0000000000000000000000000000000000000000..d0ab283b2b24138423e5fd6cc8e3076262d796f0 GIT binary patch literal 1974 zcmZuyTTdHD7(HuD)+`IyCS1ZTgoeZ{2KSP-Nkd7%Tnb$-4TRJry^QSv7VKSTcg-bz z>>ub;rAU3RD)l8&F;bEGTB%Qc?o0nepZb!h-^`lWgbFk}`+aB5%$)Om>px!o`Wt{- z_(nqmrZgCsR*@FZ85Oe{8Zjqc=2d(W!GeYe7FB$zp;^QuFhz1n#j=JrOf}KVikPj6 z!HnQD6%RCYU`=G!#f&l?FjYK^U_(O>7RB&L43g?|!Ix37so`3{_gGLp(eMSn6ic5( z@RfM^Is&F5E8tTqatfNu9(S$$oW%=y1>NQ@+h>O<@4&LRQ;X~T(3hFJ3R+6c^9~&M z4BB@dx>}zlc#|#Gx~#|*Ts{w#QG#5Wux!hpRM3zZ*-#KpJ9z@PnU>9$%f&2r*IBk8 zA}r@yj=jp=Eypc#I_A}cWK6LGKgIXC?Wd+BWLC`Y3bK|ppXK(JSgFbp&F%2qUfSh( zLRhTe$z3;95L>v&EL%Zm;&H%QV08C2-z5nom$v4V-5j5@^tQlOG5kPt!sAtcT z5!_A97EAuow4CcG!q(xSL|3VY)?CyvhH)KF;VOun8K$7;9QrISeHUBr=t$x1>K$H} z#&p^D9a61P>Y>8}U8oFK$43zMr&%FaRp1@Gt79JrB({!29FX(#%;p{uAK@7tWu95Y zCCt}q>MH1eEn27yNX=@%T!K zyG)c5`JRvnm5>3piLik;3VQ2GEQl>Jn{9JfmPAK2TerE43x>cB@+-icDOPnX$VzYn z%Tx6kbsMFfV#%>(4c7|17Nl+^{@J|c2aORF$!h$pE3nl?jqtpBH8P}sz_VR@G9 zGIg8#qTi`q6C)QJf#jl&D3W*lX<7EqISp2_yF5p&w@Ke0gFcB0k~D@y!O?dzBr1rW z0M!DGVaik6(D*)}xKJqqyfRLp7%?RoQ@*PpWL&BsY@DJo6A4GPsCEJhsHccz;!P)1 zDWj)o&WJ>i)GKH)Mk{E2L~GhICx{*+X8eL!xPrKNUVyh7A}m%&(#u4;l)QjyF_Kl% zj!cv=oyX{+bzMZ;EuI$^ToJTg0c}qv-g|<+3P$4&f+ z5&T7t{EbokL!SIgEHB9o1s~#epg$(0Q$RcEKlmK2q~A5tZ|E3ri9?0tp;`$9GEXJr z;$+($dLx_Tl%|HSGBJ7+u<=0H>lF-}ffzSvx-=TUSwZ4CqRIG(oT%X+5pMYTjZJRT zujCzc60g{#1)-Nns+gev`}ASK$C#{cH%!}w2-0*4gAP1u)-=>)Vv>Gp?-BT(+~NLz DsfWjV literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/src/LoginFrame.java b/GUI_calculator/mohit17067/src/LoginFrame.java new file mode 100644 index 0000000..4f23bf9 --- /dev/null +++ b/GUI_calculator/mohit17067/src/LoginFrame.java @@ -0,0 +1,64 @@ +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; + +public class LoginFrame extends JFrame implements ActionListener { + private JTextField useridField; + private JPasswordField passwordField; + JFrame nextFrame; + + public LoginFrame() { + setSize(300, 400); + setDefaultCloseOperation (EXIT_ON_CLOSE); + + setLayout (new GridLayout(5, 1, 10, 10)); + + JLabel useridLabel = new JLabel("User ID"); + useridLabel.setBorder(new EmptyBorder(10, 10, 10, 10)); + add (useridLabel); + + useridField = new JTextField(); + useridField.setEditable(true); + useridField.setBorder(new EmptyBorder(10, 10, 10, 10)); + add(useridField); + + JLabel passwordLabel = new JLabel("Password"); + passwordLabel.setBorder(new EmptyBorder(10, 10, 10, 10));; + add (passwordLabel); + + passwordField = new JPasswordField(20); + passwordField.setEditable(true); + passwordField.setBorder(new EmptyBorder(10, 10, 10, 10)); + add(passwordField); + + JButton loginButton = new JButton("Login"); + loginButton.addActionListener(this); + loginButton.setBorder(new EmptyBorder(10, 10, 10, 10)); + add(loginButton); + + setVisible(true); + } + + public void actionPerformed(ActionEvent e) { + if (checkCredentials()) { + nextFrame = new CalcFrame(); + } + } + + private boolean checkCredentials() { + final String userid = useridField.getText().trim(); + final String password = passwordField.getText().trim(); + return (userid.equals("Ganesh") && password.equals("Gaitonde")); + } + + public static void main(String[] args) { + JFrame loginFrame = new LoginFrame(); + } +} diff --git a/GUI_calculator/mohit17067/src/NumberPanel$1.class b/GUI_calculator/mohit17067/src/NumberPanel$1.class new file mode 100644 index 0000000000000000000000000000000000000000..31f5b6890bff8a6f37ad064a4baca6eba2622e14 GIT binary patch literal 918 zcmZuwYflqF6g|@xmM&Y{3ROT5)GFKZXz{H@6RZ%MR3*WX_;I=&%aZMEvpX&EXPHPL zn)n0!QN}xMLzloNJNLEc%-nls|Ni^+2f$OjNy5Tiy)2tZVa3EE?isjmVnPQGkk{Tr z6OXW}JzM7r28ssO4QwzNJ?`aYx6Qz643p}}4fAD&RQ*%8-4MY(m%^)1VcV6iddrZt zFI8%VLxx1vZwiKV-IZbp`@$QZ&TvP$zT6kVH$P~LCd0B_KjuAN;wP#kdP1tw&ft?> z?N>CJdEj>gN9?(pAQL&orUnw{u5>&_Q~7Y1Hhc!k$`p-ctaG=Rv?`7H*kCZ!0f9uGqi z(!s{OpBu-*Q4CAhHdc2-B?!qd9bsg+Vb`nNbM^w>7K6Uy_Mm(2I3gqo$|SDe3B1VHEV0PSVO)AmS%}gnO zI8TP0UAu}Vm~|4kN?e>OcipasSfQ(%0?h-lOh&5*kR>VUddKLU!7NpC47X^VBn$eKRL9&1^noCnX1(|m>>P>TnD}~z$x+mY(Z>`8v2!HJ m>%;70ddz4Juya_$Jn_sEPYesVLpDMG*%IXelXkMm((@m)3(}7O literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/src/NumberPanel.class b/GUI_calculator/mohit17067/src/NumberPanel.class new file mode 100644 index 0000000000000000000000000000000000000000..22e993ff7f356df605c6806057b33c8563442ef7 GIT binary patch literal 991 zcmY*YT~pIQ6g}I9rcDDBDk{**hgH)cwBR=d9PLbAwKaPWm$(j6vR5+>P#zWYmj z@xd3JQR>KyKfqW2jSu2Y%G8jD-FwfTd-vSCH^2V=_zB=9)-o8vB@M%vQZcO|i5ZQM zSrwNxlyF5u3RhKJ(~yA?I_2=#43{|-*Hz3j=uOuZe!b0uKm-h4)QaOea*bigh~ec;2Bq$`h(2sNu6WYf+Y$Z?zSAaTa6@wY%{t$Y z{OIZh294Xc2!c|zT4k6ptX{}d?uvG;97|2i4X@+dqTz(eaxvb*Ykt6Wj9^qp9u1AbHIYws7EOwzCA#08kRe$+D!9Je+Hpw3R65Vy4)&*o~%|d}rzse9M zki#r#DUpsvQgI&zGzhaWg=d(?1!CusI3YNx;-ZRi2K+%Km!{CkQ{hG03C4i=73?z^ Z4B=g=2uxFz1@aOoQeHqKG($Um{{XxD++qL# literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/src/NumberPanel.java b/GUI_calculator/mohit17067/src/NumberPanel.java new file mode 100644 index 0000000..0d1552b --- /dev/null +++ b/GUI_calculator/mohit17067/src/NumberPanel.java @@ -0,0 +1,33 @@ +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; + +public class NumberPanel extends JPanel { + private CalcFrame current_calc_state; + + public NumberPanel (CalcFrame c) { + current_calc_state = c; + + setLayout(new GridLayout(3, 3, 10, 10)); + + for (int i = 1; i < 10; i++) { + + final int num = i; + JButton NumButton = new JButton (Integer.toString (num)); + + NumButton.addActionListener (new ActionListener () { + @Override + public void actionPerformed (ActionEvent e) { + current_calc_state.writeDisplay (current_calc_state.readDisplay() + Integer.toString(num)); + } + }); + + add (NumButton); + } + + setVisible(true); + } +} diff --git a/GUI_calculator/mohit17067/src/OperationPanel$1.class b/GUI_calculator/mohit17067/src/OperationPanel$1.class new file mode 100644 index 0000000000000000000000000000000000000000..74020f483d7aa4a59bf91989747b030a62a3e5d2 GIT binary patch literal 1051 zcmZuwZBx@g5Pq%&(uP25d8wj^Vvx4Hv?#vvqEKPRnIMihIDS0R6M`YhBv;Ts;m?52 z&PZ`|#vkC1a@-3U1Zpz5-P_xJc5nB|?>|3&0hq;d7CDTn<&KU#%nZhK+`?TQ<0xfN z&Y+^y2@R7vbeL*0rL<|aR5jEz+|zKMp=+PJrXMgAtX;m(t1kDps~a+OyzMzUl{-#k z))?~EdLTkB9p8J+J>jaedB=0)BEwke@?kqvd6S`|?l%NO&T>5Qs=2o%!nb_ORTgf? zz#{zMhkK&IFj6{&;0LlQ_Jt>_OR>v}(&rRd&xYjo$2A@#82X0a3~jOMD8Rmp#ZIf6 zQJNLccKwKMwkG6`-_S5?U=R-s^kcw40ex!wkbx~2c!b9qo)~zl4C%V{h5-iVFwaoD z+^FTI<2FQSU;&E;p5eKHB~WAX7t1hb7>t*mC&IeRqew*L@egW!YggEkVK_EjzPRN? zQcxsA??q5Dl&m^;?bVR)iMTcCl4_97ZCgY%yc&&fxNSt`b3qK*GXx@nAWAg36f2*C zkPv9(RQEyXNb$mn0+)Yg7)a)Go-HbAcPMz{%&WgtZf61!hX;Z1Xv$OnLurdhx=W19 zNdJ_XMD-lep5Y2o`MjDOK$6Bte@BYGK@{oqDrw`iPm|15CXT@>lgCI^PLTdeCWdRY zc9BHvK7{K@&=(3(Fz+hgkScT>B2NnYj?Nakj!=)S+93*wwUB8cdxVK(`xE;66Lg=2 z7%lXu5E3o)lB-IdijxmfdQjRdZcxoPF+%S&MzIN#EI=pHgT-;GW;hN}4nPN8|2Aew L)2ZGZNqYVQo5k~z literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/src/OperationPanel.class b/GUI_calculator/mohit17067/src/OperationPanel.class new file mode 100644 index 0000000000000000000000000000000000000000..d8c5abf2cd9a3f60bd84e98ad0c10c801091e80f GIT binary patch literal 1117 zcmZWo+fvg|6kVscq#-~_0YyLsLE2PELA-HMp$ftjbc}-&9fvuz875LvCP@Jw^vN&r z#aEpXn32&B@WCJOPka#f2@JN9%(?8#*?aB1&iV1@>vsU-SWKb=Lkc>Pk&u<4%gD*N zCSzE}hzvuR^AbiCG+|63;ktxz1ueKC;iiHVZVBPGu-p;TgoH^6Qw-{Y>)KwS!hPTN z8MIQ(^K3U*E%8ce)em@JGc*+oB+Yqz)1G9ASGR1BT+=U$ulY7ND%@Q+%)oQpb+RU= z9M=i%GPGpsPGwgZVufm%g0&VM*Iuq|uG!u*zE&Ykvl;Nx#uDEOK@;B95AcEafaUU}$_Fco@p&l5Ev$Y_oy23t7 z$r`~7j0$~0#REK4F^72-kFY@9YIGwaM9R~UVa*K5QyvIjMl@B*EYK%*N#72Rkuh{< zj;Rrdk9AAjc`}WTvu1hqJL8ZAFF?ymodW=)_DrX3L5$!OkrdK$J4Gh5}-7a*zC9lhLB8|uq z3W!SRlhDtA-xyEHxPpO`LPf!(Mx4O0PqbkW`4XX0rY;SV6v0)B4=AKf(MsQ6)JOQZ literal 0 HcmV?d00001 diff --git a/GUI_calculator/mohit17067/src/OperationPanel.java b/GUI_calculator/mohit17067/src/OperationPanel.java new file mode 100644 index 0000000..1446028 --- /dev/null +++ b/GUI_calculator/mohit17067/src/OperationPanel.java @@ -0,0 +1,44 @@ +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; + +public class OperationPanel extends JPanel { +private CalcFrame current_calc_state; + + private final String opers[] = {"+", "-", "x", "/", "=", "CLR"}; + + public OperationPanel (CalcFrame c) { + setLayout(new GridLayout(2, 3, 10, 10)); + + current_calc_state = c; + + for (int i = 0; i < opers.length; i++) { + + final String op = opers[i]; + JButton OpButton = new JButton (op); + + OpButton.addActionListener (new ActionListener () { + + @Override + public void actionPerformed (ActionEvent e) { + if (op == "=") { + current_calc_state.evaluateExpression(); + } + else if (op == "CLR"){ + current_calc_state.writeDisplay (""); + } + else { + current_calc_state.writeDisplay (current_calc_state.readDisplay() + op); + } + } + }); + + add (OpButton); + } + + setVisible(true); + } +}