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 */
1618
1719package simplejavacalculator ;
@@ -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 ;
36+ butCos , butSin , butTan , butxpowerofy , butlog , butrate ;
3537 private final Calculator calc ;
3638
3739 private final String [] buttonValue = { "0" , "1" , "2" , "3" , "4" , "5" , "6" ,
@@ -59,6 +61,9 @@ 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%" );
6267
6368 butCancel = new JButton ("C" );
6469
@@ -67,15 +72,17 @@ public UI() {
6772
6873 public void init () {
6974 frame .setVisible (true );
70- frame .setSize (350 , 280 );
75+ frame .setSize (330 , 300 );
7176 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
7277 frame .add (panel );
7378
7479 panel .add (text );
75- for (int i = 0 ; i < 10 ; i ++) {
80+
81+ for (int i = 1 ; i < 10 ; i ++) {
7682 panel .add (but [i ]);
7783 but [i ].addActionListener (this );
7884 }
85+ panel .add (but [0 ]);
7986
8087 panel .add (butAdd );
8188 panel .add (butMinus );
@@ -87,6 +94,9 @@ public void init() {
8794 panel .add (butCos );
8895 panel .add (butSin );
8996 panel .add (butTan );
97+ panel .add (butxpowerofy );
98+ panel .add (butlog );
99+ panel .add (butrate );
90100
91101 panel .add (butEqual );
92102 panel .add (butCancel );
@@ -101,6 +111,9 @@ public void init() {
101111 butCos .addActionListener (this );
102112 butSin .addActionListener (this );
103113 butTan .addActionListener (this );
114+ butxpowerofy .addActionListener (this );
115+ butlog .addActionListener (this );
116+ butrate .addActionListener (this );
104117
105118 butEqual .addActionListener (this );
106119 butCancel .addActionListener (this );
@@ -134,6 +147,10 @@ public void actionPerformed(ActionEvent e) {
134147 writer (calc
135148 .calculateBi (Calculator .BiOperatorModes .divide , reader ()));
136149 }
150+ if (source == butxpowerofy ) {
151+ writer (calc
152+ .calculateBi (Calculator .BiOperatorModes .xpowerofy , reader ()));
153+ }
137154
138155 if (source == butSquare ) {
139156 writer (calc .calculateMono (Calculator .MonoOperatorModes .square ,
@@ -164,6 +181,14 @@ public void actionPerformed(ActionEvent e) {
164181 writer (calc .calculateMono (Calculator .MonoOperatorModes .tan ,
165182 reader ()));
166183 }
184+ if (source == butlog ) {
185+ writer (calc .calculateMono (Calculator .MonoOperatorModes .log ,
186+ reader ()));
187+ }
188+ if (source == butrate ) {
189+ writer (calc .calculateMono (Calculator .MonoOperatorModes .rate ,
190+ reader ()));
191+ }
167192
168193 if (source == butEqual ) {
169194 writer (calc .calculateEqual (reader ()));
0 commit comments