public class event implements ActionListener{ public void actionPerformed(ActionEvent operations){ String check = operations.getActionCommand(); if(check.equals("Add")){ try{ field1.setText(""); field2.setText(""); field3.setText(""); popup.setText("" + trademark); double num1, num2, answer; field2.setVisible(false); mainprompt.setText("Enter Numbers Below"); prompt1.setText("Number"); prompt2.setText("+"); prompt3.setText("Number"); num1 = Double.parseDouble(field1.getText()); num2 = Double.parseDouble(field3.getText()); answer = num1 + num2; popup.setText("The sum of " + num1 + " and " + num2 + " is " + answer + "."); mainprompt.setText("Choose Operation Above"); //Reset Fields Once Answer is Received prompt1.setText("Number"); prompt2.setText("Number"); prompt3.setText("Number"); field1.setVisible(true); field2.setVisible(true); field3.setVisible(true); field1.setText(""); field2.setText(""); field3.setText(""); }catch(Exception e){ //Fixes another error prompt1.setText("Number"); prompt2.setText("+"); prompt3.setText("Number"); field1.setVisible(true); field2.setVisible(false); field3.setVisible(true); field1.setText(""); field2.setText(""); field3.setText(""); } } } }
This portion of code adds functionality to my "Add" button. I have an "Answer" button created, that currently does nothing. I'm trying to place that "Answer" button within the if statement so that if the user clicks the button, it will return (popup.setText("The sum of " + num1 + " and " + num2 + " is " + answer + ".")).
If more code is needed, I'll put up my condensed version of my calculator (183 lines).