From b96706cab46dcc6f41e152419aa253f280917e3e Mon Sep 17 00:00:00 2001 From: Muhammad Anas Rashid Date: Fri, 29 Jan 2016 19:08:28 +0500 Subject: [PATCH] Help to improve java swing calculator made on eclipse --- .classpath | 6 + .project | 17 +++ .settings/org.eclipse.jdt.core.prefs | 11 ++ bin/Calculator$1.class | Bin 0 -> 783 bytes bin/Calculator$2.class | Bin 0 -> 784 bytes bin/Calculator$3.class | Bin 0 -> 784 bytes bin/Calculator$4.class | Bin 0 -> 784 bytes bin/Calculator$5.class | Bin 0 -> 784 bytes bin/Calculator$6.class | Bin 0 -> 1997 bytes bin/Calculator.class | Bin 0 -> 3144 bytes src/Calculator.java | 170 +++++++++++++++++++++++++++ 11 files changed, 204 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 bin/Calculator$1.class create mode 100644 bin/Calculator$2.class create mode 100644 bin/Calculator$3.class create mode 100644 bin/Calculator$4.class create mode 100644 bin/Calculator$5.class create mode 100644 bin/Calculator$6.class create mode 100644 bin/Calculator.class create mode 100644 src/Calculator.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fceb480 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..d761300 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + GUICalc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bin/Calculator$1.class b/bin/Calculator$1.class new file mode 100644 index 0000000000000000000000000000000000000000..51369695f2711b557648fc8848031cddd5a7cdfc GIT binary patch literal 783 zcmY*XT~8B16g|@}Y+V)#{Xjsl6|1&XsYc&wd}$!jERtB#M17iWCos6(ZFaZ9ga5~8 zUchML5Aa7B&u$x9H<_KebMKsc?z#8R-=Dt$yh6)FM!@b!&mDU*4#L_C6NbR*x%?_y zp7c*!$Nh8V#wHd83bWe}W8as3PYEo(*1nG42xRMxo`BH_2FgMfOEyg81oDpd)%)?V zufmhbi-Hrl((B1kC-(Hxh|hE+u;R>fX%jUZ`z8tk*34mH4NJ+dY-1gF1#;4LRTR~p z3+&eC5ZVnVp?ukjE;LJdcNof{YFpUEJri5gg8ui~*v1aCMJn#;NT($l^-qnSg$f>+ zs0tKkG8|mGY830hx3QZRI|{WQcVp>(ISHkk$ivKo;DRF0^AZsBl~Z;TnQxI;^KuGs zBu7(itZpz4U3I7vz4J32_7ft!Iq+RCh*;r~iqC?9ji-3VP7I~?1=j1I=hAdz5u|=S5l(0jq zk|wG$hG5e~ImSFhjR+-Dd4$J2J)xh2-8E4$7+j~BK?8f-4NgrH`#f0;Ov>W-5022D Ax&QzG literal 0 HcmV?d00001 diff --git a/bin/Calculator$2.class b/bin/Calculator$2.class new file mode 100644 index 0000000000000000000000000000000000000000..b17ab32575d96a76b2d7c87beb2239fe25101d86 GIT binary patch literal 784 zcmaKq-)_?|6vjU{rP;EugtCo)8{1fbHXQ^_+zpVR8WJc2#Jb+Qso6Yv33A+S;;oPv zNL=s$JQU(MRO&PkksSNj=lnjOFZucF`wsw*@xVom!S8aFjTAS9j<#IX8Nwqz=859@ zLGpHRBr@Zo!LU;8@)MJYvB*vGJTtP$Q&}333(e3lhq8y!_KqO8UfnM?DGVWV}v{9noKK101*48<%M0v|4B?COe-S$G~CT=g-B z1qP>OQ-f6I;?3xIAasuplwfG4MaEU1YiZ-jX5C(&Vg8(Yv_%&Sc-7}Sp+6M*SPU6f zTh*E2cJ$a)9NY34$VQ_Im3Lsd4@3lhUVug zagp9$RX}QZk0pw2A*JIQuG7qL12-qA7nEt?Ui^jBZhghdMM{sZuwPM@{$x%lR%HVb ZaU9$wLJjwDpXNGRh_PvzbY^ww`3)7@s_g&( literal 0 HcmV?d00001 diff --git a/bin/Calculator$3.class b/bin/Calculator$3.class new file mode 100644 index 0000000000000000000000000000000000000000..5112724a30434af259a972c250a8bd3f0e5d1ba3 GIT binary patch literal 784 zcmaKqT~E|N6o%i~u3IRT*5$)55R?kL1*{3)p(eV)L{roRvUf&jy8{dvS~Hzpi2uq& zH1Wb8;Eyt%shcc8W0UF3nK|cq=e+IDU*CTKc!W(CH3q-KRW?xE6gt{+QD+E``H&}y z=ZDFg-m%Dxiw47DwaZUUB8DP2$+OJJB2Q&$L@qQ#!yL&ndPu-@Ox&h$$W>H)6xu2< z%%+xemXxQG_^(pl6N<7Lk7X{+Q-+n+#qxh8x4R7WPSF>WUd_WmEZ|k2Z-qW6^oi&* zEVZgzC6}$(v9@ftyAxPoV4EK9VA;hI>HXcYkGr_X;FiMdi!;M8H-c8K?-@){f$3DM~Dp!48cpsD+_*90;4%Z~BpHG^XIw=~Y@iq1d50h}X|C9dDc?jK87z zxk{X)w^tRA8s1@^Vp~Y*xQ-h%Gu*_j5$ZW*TDTW~A+_6Iv3QyCp04nrqRjuv98s*w b3L@e-xKD%{RRv4G9!Jq)ipKZtATrUV-!G?9XxPRWAM9NWn;xnp`(tAIzu?(6P_rZ zA0==5Bas;w4Tkkjp32gQTxf=d8OkzxM8I@L+@)~BRaATw+A1(C zrT2JX1wU%-6yUi-C(a)y&d-Y+JuP`w1jh@)J?~ zmpOgbuHt1WN^FwB4vkBwg`ssE2%FY#`jKih7U0wAWm-L<*r7Ryx6iN`@0=lwzoGfL zN?f70R~3*NhFGQ87E(H{;u_5i*KuQtdQO=Z?!{k7?dDgkU!;ua3Lh%U>YvOh#j0!} aB94Q*M5y5&?$caH3o&*qlg_LzJ--2gk*i<; literal 0 HcmV?d00001 diff --git a/bin/Calculator$5.class b/bin/Calculator$5.class new file mode 100644 index 0000000000000000000000000000000000000000..b27ace89b613f4bad2ceb6452d5bbda56b974aa7 GIT binary patch literal 784 zcmaKq-)_?|6vjU{rP;EugtCo)8yhS@n+?JRyBZ)tH6&05NSk`^re^cx#mI5HiMK*x zAaTJ1@KA{3P^r^EL~`t7pY!{CzU1ex?>_)M!9yPnhOoy~F;d)WlWh5DGQ>xG%rnKy zgY4blNEFsbi(#eSO>O%P0j~GQC91zETw(Uu--Xe{;%Y2pP|{)Loo}6D1?t0x4IHy7C`_HS3}HU zfx+vz)F_vwcsn{C2(!-zN-(r@U2xUsM!I;i*>u-um_MhUY|+IcUibN4m=D?_;4Xt-3A-;&EyLmjTD!hy4VgnIYLuG; z@^txsk_^F~9+^VClCHgIYX2jrOglSep>##eU11OP&_|bQrfDHIoL_bVxTY-q$(&G}$~qF_ Yc(_M|2JYhl%}sQWV$(6{%<0ne8%@EhS^xk5 literal 0 HcmV?d00001 diff --git a/bin/Calculator$6.class b/bin/Calculator$6.class new file mode 100644 index 0000000000000000000000000000000000000000..d0775db95fae3496296831579c38c0fd7eb9441c GIT binary patch literal 1997 zcma)6TW=dx5dKc$WS#A%c1_|Yp`{L_U^_|OLYfrPQqmBY7Ux2pnx;U~wSAIoy4kh7 zo1|0%A%qYJ5CVjt;wFRyydq(zq7n~Cyzs_<;0N#yLd@(svR$eK%X=RWC~Zc58d zO%z=UKBS!%#O;&Xz$gF3!sv zZrYG$k(3YIrMz^4@K|P-WSOrh(A8|6(eu(IOO>^B%h~eoa@w#A_ep`3c;jW7E$e>& zpWOG#`_tB<|fg zbvJcWOyhVWr{ZD66+9vky*Do!5=aUtE7Ikh5e4yt59!rN)-4l{<0^)5Ou=wd{rG1Z zQlP?63}M)7D)TV|aoy zNWll<)nG)&@Y@=BGnA!nBbj^4{_L!_QR3Umx<4d?L; zRoyaQA;$n-RB1lE$iUBXn$nGV@~st2Q$5sU@H2F7!!V1o9K@_Z$AnkKu`@9h89c|K zjWTRj!#wj4bZy^=k8>KH#}(>6y;PDGu|2#;3{CzhmJG6-u#q5Mq{Ivdu}IUEAgaWN#P8Uh0tb%DfRBY4IUA2n}Ok$v}rorMiQn~jH-860zigv-G*J;w! z9Y;EdQQx)F*M_!mnA;QxN4QD7nOfAFsX@J&+LPYN7WzU6lhpxQ&CtG`=2&vDf=F_x zg0AFn1<_=0pn{%cZ(9X@$!#3^!LvLPhclY+>Iv9-pS;o+?g9&VGxtHGtcgsA8&S z=Wp`2ae-C)?jW-enc2qNP!*S|xLn0T6<5E*A3HcN?25Cz7tZH9I4|vrv$hw`{0`32 zt~l0SIGo46h)yvwHLYN37IBcq*NEoV5ycxs#hdhqy+x1F+nB&RxQ2Ie6Yt>_yibx3 z@I5}nFZc+*;$!@dPw*!`6)J9tPJAYM@r5{rFU2K%B`)J@v50Rxx??`2HM)sh6i_6> xPl_ZYmZ>;a=nh>_qTPREPQln;IPd?1WVuRbEikY~a{$+|4x3gg*>e%m?_U&p?PLG| literal 0 HcmV?d00001 diff --git a/bin/Calculator.class b/bin/Calculator.class new file mode 100644 index 0000000000000000000000000000000000000000..e9ff2b7e46c0c953abb7f9789ab85485392ce5a8 GIT binary patch literal 3144 zcmaJ@+jAS`75{x}NxNFFRQ_p00W*Ghe9{SJ+hL;XceQP^CXLlt_?nScq`}Umk z{m%V-`t)Caz71d}K9nH|s5!$fRBgj|D>7mN`UPXb$k>Kc%8bulFblpw$GJ**MM~h# zJj*O*yvr6z9T}|{Wiu-fD;t(0(3^fN;D;C|{R#viwi2+(4j)$ z9u4=hu`1hY8Mbwm&|?01iw-gm5al;|p-gIB+5_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zbX$3HtS1*ppGe zo|T62bFyFH6)A~d&`!c_@mIWx*QnRO79Znv+QmeVc!4~86LC=zd+`?S5@gli@HXva zvf~~4z6pgipTxVgOX>=KiC=}20Gnv#krL<9{Vi?6nUn~Koq<_Aog};$Jm1F$v~H&n WN8=;-c+q-2T5m+_&1k(9uKxyq!1sIr literal 0 HcmV?d00001 diff --git a/src/Calculator.java b/src/Calculator.java new file mode 100644 index 0000000..a0e3b7e --- /dev/null +++ b/src/Calculator.java @@ -0,0 +1,170 @@ +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JButton; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import java.awt.Font; +import javax.swing.JTextField; +import java.awt.Color; + +public class Calculator { + + private JFrame frmCalculator; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Calculator window = new Calculator(); + + window.frmCalculator.setVisible(true); + + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public Calculator() { + initialize(); + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frmCalculator = new JFrame(); + frmCalculator.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 18)); + frmCalculator.setTitle("Calculator"); + frmCalculator.setResizable(false); + frmCalculator.setBounds(100, 100, 293, 230); + frmCalculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frmCalculator.getContentPane().setLayout(null); + JLabel operator = new JLabel(""); + operator.setFont(new Font("Tahoma", Font.BOLD, 13)); + operator.setHorizontalAlignment(SwingConstants.CENTER); + operator.setBounds(126, 22, 36, 23); + frmCalculator.getContentPane().add(operator); + + JLabel answer = new JLabel(""); + answer.setHorizontalAlignment(SwingConstants.CENTER); + answer.setBounds(48, 161, 187, 23); + frmCalculator.getContentPane().add(answer); + + JTextField dtrpnNumber = new JTextField(); + dtrpnNumber.setFont(new Font("Tahoma", Font.PLAIN, 12)); + dtrpnNumber.setBounds(10, 22, 106, 23); + //Border b = null; + //b.paintBorder(dtrpnNumber, null, 0, 0, 1, 1); + //dtrpnNumber.setBorder(1); + frmCalculator.getContentPane().add(dtrpnNumber); + + JTextField dtrpnNumber_1 = new JTextField(); + dtrpnNumber_1.setBounds(170, 22, 106, 23); + frmCalculator.getContentPane().add(dtrpnNumber_1); + + + + JButton plus = new JButton("+"); + plus.setBackground(Color.LIGHT_GRAY); + plus.setFont(new Font("Tahoma", Font.PLAIN, 18)); + plus.setIcon(null); + plus.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + operator.setText("+"); + } + }); + plus.setBounds(10, 56, 106, 23); + frmCalculator.getContentPane().add(plus); + + JButton minus = new JButton("-"); + minus.setBackground(Color.LIGHT_GRAY); + minus.setFont(new Font("Tahoma", Font.PLAIN, 28)); + minus.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + operator.setText("-"); + } + }); + minus.setBounds(10, 93, 106, 23); + frmCalculator.getContentPane().add(minus); + + JButton multiply = new JButton("x"); + multiply.setBackground(Color.LIGHT_GRAY); + multiply.setFont(new Font("Tahoma", Font.PLAIN, 18)); + multiply.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + operator.setText("X"); + } + }); + multiply.setBounds(170, 56, 106, 23); + frmCalculator.getContentPane().add(multiply); + + JButton division = new JButton("/"); + division.setBackground(Color.LIGHT_GRAY); + division.setFont(new Font("Tahoma", Font.PLAIN, 18)); + division.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + operator.setText("/"); + } + }); + division.setBounds(170, 93, 106, 23); + frmCalculator.getContentPane().add(division); + + JButton equal = new JButton("="); + equal.setBackground(new Color(192, 192, 192)); + equal.setFont(new Font("Tahoma", Font.PLAIN, 18)); + equal.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(dtrpnNumber.getText().isEmpty()) + { + dtrpnNumber.setText("0"); + } + if(dtrpnNumber_1.getText().isEmpty()) + { + dtrpnNumber_1.setText("0"); + } + Float ans = new Float(0); + if(operator.getText() == "+") + { + ans= Float.valueOf(dtrpnNumber.getText())+Float.valueOf(dtrpnNumber_1.getText()); + answer.setText("Answer = "+ans.toString()); + } + else + if(operator.getText() == "-") + { + ans= Float.valueOf(dtrpnNumber.getText())-Float.valueOf(dtrpnNumber_1.getText()); + answer.setText("Answer = "+ans.toString()); + } + else + if(operator.getText() == "X") + { + ans= Float.valueOf(dtrpnNumber.getText())*Float.valueOf(dtrpnNumber_1.getText()); + answer.setText("Answer = "+ans.toString()); + } + else + if(operator.getText() == "/") + { + ans= Float.valueOf(dtrpnNumber.getText())/Float.valueOf(dtrpnNumber_1.getText()); + answer.setText("Answer = "+ans.toString()); + } + else + answer.setText("No Operator is Selected!!!"); + + } + }); + equal.setBounds(114, 127, 61, 23); + frmCalculator.getContentPane().add(equal); + + + } +}