1010 * @create 2012-03-30
1111 *
1212 * @modifiedby Achintha Gunasekara
13+ * @modifiedby Kydon Chantzaridis
1314 * @modweb http://www.achinthagunasekara.com
1415 * @modemail contact@achinthagunasekara.com
16+ * @modemail kchantza@csd.auth.gr
1517 */
1618package simplejavacalculator ;
1719
@@ -31,7 +33,7 @@ public class UI implements ActionListener {
3133 private final JTextArea text ;
3234 private final JButton but [], butAdd , butMinus , butMultiply , butDivide ,
3335 butEqual , butCancel , butSquareRoot , butSquare , butOneDevidedBy ,
34- butCos , butSin , butTan , butBinary ;
36+ butCos , butSin , butTan , butxpowerofy , butlog , butrate , butabs , butBinary ;
3537 private final Calculator calc ;
3638
3739 private final String [] buttonValue = {"0" , "1" , "2" , "3" , "4" , "5" , "6" ,
@@ -59,6 +61,10 @@ public UI() {
5961 butCos = new JButton ("Cos" );
6062 butSin = new JButton ("Sin" );
6163 butTan = new JButton ("Tan" );
64+ butxpowerofy = new JButton ("x^y" );
65+ butlog = new JButton ("log10(x)" );
66+ butrate = new JButton ("x%" );
67+ butabs = new JButton ("abs(x)" );
6268
6369 butCancel = new JButton ("C" );
6470 butBinary = new JButton ("Bin" );
@@ -68,15 +74,18 @@ public UI() {
6874
6975 public void init () {
7076 frame .setVisible (true );
71- frame .setSize (350 , 280 );
77+ frame .setSize (330 , 300 );
7278 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
7379 frame .add (panel );
7480
7581 panel .add (text );
76- for (int i = 0 ; i < 10 ; i ++) {
82+
83+ for (int i = 1 ; i < 10 ; i ++) {
7784 panel .add (but [i ]);
7885 but [i ].addActionListener (this );
7986 }
87+ panel .add (but [0 ]);
88+ but [0 ].addActionListener (this );
8089
8190 panel .add (butAdd );
8291 panel .add (butMinus );
@@ -88,6 +97,11 @@ public void init() {
8897 panel .add (butCos );
8998 panel .add (butSin );
9099 panel .add (butTan );
100+ panel .add (butxpowerofy );
101+ panel .add (butlog );
102+ panel .add (butrate );
103+ panel .add (butabs );
104+ panel .add (butabs );
91105 panel .add (butBinary );
92106
93107 panel .add (butEqual );
@@ -103,9 +117,14 @@ public void init() {
103117 butCos .addActionListener (this );
104118 butSin .addActionListener (this );
105119 butTan .addActionListener (this );
120+ butxpowerofy .addActionListener (this );
121+ butlog .addActionListener (this );
122+ butrate .addActionListener (this );
123+ butabs .addActionListener (this );
124+ butBinary .addActionListener (this );
125+
106126 butEqual .addActionListener (this );
107127 butCancel .addActionListener (this );
108- butBinary .addActionListener (this );
109128 }
110129
111130 @ Override
@@ -129,43 +148,58 @@ public void actionPerformed(ActionEvent e) {
129148
130149 if (source == butMultiply ) {
131150 writer (calc .calculateBi (Calculator .BiOperatorModes .multiply ,
132- reader ()));
151+ reader ()));
133152 }
134153
135154 if (source == butDivide ) {
136155 writer (calc
137- .calculateBi (Calculator .BiOperatorModes .divide , reader ()));
156+ .calculateBi (Calculator .BiOperatorModes .divide , reader ()));
157+ }
158+ if (source == butxpowerofy ) {
159+ writer (calc
160+ .calculateBi (Calculator .BiOperatorModes .xpowerofy , reader ()));
138161 }
139162
140163 if (source == butSquare ) {
141164 writer (calc .calculateMono (Calculator .MonoOperatorModes .square ,
142- reader ()));
165+ reader ()));
143166 }
144167
145168 if (source == butSquareRoot ) {
146169 writer (calc .calculateMono (Calculator .MonoOperatorModes .squareRoot ,
147- reader ()));
170+ reader ()));
148171 }
149172
150173 if (source == butOneDevidedBy ) {
151174 writer (calc .calculateMono (
152- Calculator .MonoOperatorModes .oneDevidedBy , reader ()));
175+ Calculator .MonoOperatorModes .oneDevidedBy , reader ()));
153176 }
154177
155178 if (source == butCos ) {
156179 writer (calc .calculateMono (Calculator .MonoOperatorModes .cos ,
157- reader ()));
180+ reader ()));
158181 }
159182
160183 if (source == butSin ) {
161184 writer (calc .calculateMono (Calculator .MonoOperatorModes .sin ,
162- reader ()));
185+ reader ()));
163186 }
164187
165188 if (source == butTan ) {
166189 writer (calc .calculateMono (Calculator .MonoOperatorModes .tan ,
167- reader ()));
190+ reader ()));
191+ }
192+ if (source == butlog ) {
193+ writer (calc .calculateMono (Calculator .MonoOperatorModes .log ,
194+ reader ()));
195+ }
196+ if (source == butrate ) {
197+ writer (calc .calculateMono (Calculator .MonoOperatorModes .rate ,
198+ reader ()));
168199 }
200+ if (source == butabs ){
201+ writer (calc .calculateMono (Calculator .MonoOperatorModes .abs , reader ()));
202+ }
169203
170204 if (source == butEqual ) {
171205 writer (calc .calculateEqual (reader ()));
0 commit comments