@@ -26,22 +26,23 @@ public class UI implements ActionListener {
2626 private JFrame frame ;
2727 private JPanel panel ;
2828 private JTextArea text ;
29- private JButton but1 , but2 , but3 , but4 , but5 , but6 , but7 , but8 , but9 , but0 , butAdd , butMinus , butMultiply , butDivide , butEqual , butCancel ;
29+ private JButton but1 , but2 , but3 , but4 , but5 , but6 , but7 , but8 , but9 , but0 , butAdd , butMinus , butMultiply , butDivide , butEqual , butCancel , butSquareRoot , butSquare , butOneDevidedBy , butCos , butSin , butTan ;
3030 private Double num1 , num2 , result ;
3131 private int add = 0 , minus = 0 , multiply = 0 , divide = 0 ;
3232
3333 public UI () {
3434 frame = new JFrame ("Calculator PH" );
35+ frame .setResizable (false );
3536 panel = new JPanel (new FlowLayout ());
3637
37- text = new JTextArea (1 , 20 );
38+ text = new JTextArea (2 , 25 );
3839 but1 = new JButton ("1" );
39- but2 = new JButton ("2" );
40+ but2 = new JButton ("2" );
4041 but3 = new JButton ("3" );
4142 but4 = new JButton ("4" );
4243 but5 = new JButton ("5" );
4344 but6 = new JButton ("6" );
44- but7 = new JButton ("7" );
45+ but7 = new JButton ("7" );
4546 but8 = new JButton ("8" );
4647 but9 = new JButton ("9" );
4748 but0 = new JButton ("0" );
@@ -51,14 +52,20 @@ public UI() {
5152 butMultiply = new JButton ("*" );
5253 butDivide = new JButton ("/" );
5354 butEqual = new JButton ("=" );
55+ butSquareRoot = new JButton ("√" );
56+ butSquare = new JButton ("x*x" );
57+ butOneDevidedBy = new JButton ("1/x" );
58+ butCos = new JButton ("Cos" );
59+ butSin = new JButton ("Sin" );
60+ butTan = new JButton ("Tan" );
5461
5562 butCancel = new JButton ("C" );
5663
5764 }
5865
5966 public void init () {
6067 frame .setVisible (true );
61- frame .setSize (250 , 250 );
68+ frame .setSize (350 , 280 );
6269 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
6370 frame .add (panel );
6471
@@ -78,8 +85,14 @@ public void init() {
7885 panel .add (butMinus );
7986 panel .add (butMultiply );
8087 panel .add (butDivide );
81- panel .add (butEqual );
88+ panel .add (butSquare );
89+ panel .add (butSquareRoot );
90+ panel .add (butOneDevidedBy );
91+ panel .add (butCos );
92+ panel .add (butSin );
93+ panel .add (butTan );
8294
95+ panel .add (butEqual );
8396 panel .add (butCancel );
8497
8598 but1 .addActionListener (this );
@@ -97,8 +110,14 @@ public void init() {
97110 butMinus .addActionListener (this );
98111 butMultiply .addActionListener (this );
99112 butDivide .addActionListener (this );
100- butEqual .addActionListener (this );
113+ butSquare .addActionListener (this );
114+ butSquareRoot .addActionListener (this );
115+ butOneDevidedBy .addActionListener (this );
116+ butCos .addActionListener (this );
117+ butSin .addActionListener (this );
118+ butTan .addActionListener (this );
101119
120+ butEqual .addActionListener (this );
102121 butCancel .addActionListener (this );
103122
104123 }
@@ -191,6 +210,42 @@ public void actionPerformed(ActionEvent e) {
191210 multiply = 0 ;
192211 divide = 1 ;
193212 }
213+
214+ if (source == butSquare ) {
215+ num1 = reader ();
216+ result = num1 *num1 ;
217+ text .setText (Double .toString (result ));
218+ }
219+
220+ if (source == butSquareRoot ) {
221+ num1 = reader ();
222+ result = Math .sqrt (num1 );
223+ text .setText (Double .toString (result ));
224+ }
225+
226+ if (source == butOneDevidedBy ) {
227+ num1 = reader ();
228+ result = 1 /num1 ;
229+ text .setText (Double .toString (result ));
230+ }
231+
232+ if (source == butCos ) {
233+ num1 = reader ();
234+ result = Math .cos (num1 );
235+ text .setText (Double .toString (result ));
236+ }
237+
238+ if (source == butSin ) {
239+ num1 = reader ();
240+ result = Math .sin (num1 );
241+ text .setText (Double .toString (result ));
242+ }
243+
244+ if (source == butTan ) {
245+ num1 = reader ();
246+ result = Math .tan (num1 );
247+ text .setText (Double .toString (result ));
248+ }
194249
195250 if (source == butEqual ) {
196251 num2 = reader ();
0 commit comments