@@ -15,8 +15,8 @@ public class SwingCalculator
1515 static JFrame calcBox ;
1616
1717 //create 2 text boxes for text input
18- static final JTextField textInput1 = new JTextField ("Enter Your First Integer" );
19- static final JTextField textInput2 = new JTextField ("Enter Your Second Integer" );
18+ static final JTextField intInput1 = new JTextField ("Enter Your First Integer" );
19+ static final JTextField intInput2 = new JTextField ("Enter Your Second Integer" );
2020
2121 //create an object out of the ConsoleCalculator script
2222 static ConsoleCalculator calculator = new ConsoleCalculator ();
@@ -53,17 +53,17 @@ public static void setup()
5353 division .addActionListener (divideButton );
5454
5555 //connects Action Listeners to corresponding text fields
56- textInput1 .addActionListener (text1 );
57- textInput2 .addActionListener (text2 );
56+ intInput1 .addActionListener (text1 );
57+ intInput2 .addActionListener (text2 );
5858
5959 //adds buttons to window/GUI
60- calcBox .add (textInput1 );
60+ calcBox .add (intInput1 );
6161 calcBox .setLayout (new FlowLayout ());
6262 calcBox .add (addition );
6363 calcBox .add (subtraction );
6464 calcBox .add (multiplication );
6565 calcBox .add (division );
66- calcBox .add (textInput2 );
66+ calcBox .add (intInput2 );
6767
6868
6969
@@ -84,7 +84,7 @@ public void actionPerformed(ActionEvent buttonPress)
8484 //what happens when button is pressed
8585 //sets the number1 variable to what the user puts in the text box
8686 //Float.parseFloat changes input from a String to a float
87- ConsoleCalculator .number1 = Float .parseFloat (textInput1 .getText ());
87+ ConsoleCalculator .number1 = Float .parseFloat (intInput1 .getText ());
8888 }
8989 }
9090
@@ -97,7 +97,7 @@ public void actionPerformed(ActionEvent buttonPress)
9797 //what happens when button is pressed
9898 //sets the number2 variable to what the user puts in the text box
9999 //Float.parseFloat changes input from a String to a float
100- ConsoleCalculator .number2 = Float .parseFloat (textInput2 .getText ());
100+ ConsoleCalculator .number2 = Float .parseFloat (intInput2 .getText ());
101101 }
102102 }
103103
@@ -110,9 +110,10 @@ public void actionPerformed(ActionEvent buttonPress)
110110 {
111111 //what happens when button is pressed
112112 System .out .println ("Addition Selected" );
113- calculator .doSum ();
114- JLabel label = new JLabel (Float . toString ( ConsoleCalculator . answer ));
113+ // calculator.doSum();
114+ JLabel label = new JLabel (" = " + calculator . doSum ( ));
115115 calcBox .add (label );
116+
116117 calcBox .invalidate ();
117118 calcBox .validate ();
118119 calcBox .repaint ();
@@ -128,8 +129,7 @@ public void actionPerformed(ActionEvent buttonPress)
128129 {
129130 //what happens when button is pressed
130131 System .out .println ("Subtraction Selected" );
131- calculator .doDifference ();
132- JLabel label = new JLabel (Float .toString (ConsoleCalculator .answer ));
132+ JLabel label = new JLabel (" = " + calculator .doDifference ());
133133 calcBox .add (label );
134134
135135 //reloads the GUI
@@ -148,10 +148,9 @@ public void actionPerformed(ActionEvent buttonPress)
148148 {
149149 //what happens when button is pressed
150150 System .out .println ("Multiplication Selected" );
151- calculator .doProduct ();
152151
153152 //creates new text to display answer
154- JLabel label = new JLabel (Float . toString ( ConsoleCalculator . answer ));
153+ JLabel label = new JLabel (" = " + calculator . doProduct ( ));
155154
156155 //reloads the GUI
157156 calcBox .add (label );
@@ -169,10 +168,10 @@ public void actionPerformed(ActionEvent buttonPress)
169168 {
170169 //what happens when button is pressed
171170 System .out .println ("Division Selected" );
172- calculator . doQuotient ();
171+
173172
174173 //creates new text to display answer
175- JLabel label = new JLabel (Float . toString ( ConsoleCalculator . answer ));
174+ JLabel label = new JLabel (" = " + calculator . doQuotient ( ));
176175 calcBox .add (label );
177176
178177 //reloads the GUI
0 commit comments