Question: Java Create a New Class: Right-click your project (Lab04) and Select New-->Class and name it Calculator. Start by creating a private JFrame field and an

Java

  1. Create a New Class: Right-click your project (Lab04) and Select New-->Class and name it Calculator.
  2. Start by creating a private JFrame field and an accessor that returns it (getFrame). The JUnit tests rely on this accessor to test your GUI. Now, as you make progress, you can run the JUnits to see your grade improve. Create your constructor to initialize your frame.
  3. To actually run your program (to test it manually), create a main method and in it simply create a Calculator: Calculator calc = new Calculator(). You should not add any more lines to your main method.
  4. Now you should be able to run your program and run the JUnits. However, none of the JUnits should pass because you havent built your GUI. All initialization should occur inside the Calculator constructor / initializeComponents methods. You can scroll down to see pictures of what the calculator should look like at the end.
  5. Create a frame with an appropriate title for the calculator.
  6. Create a button panel.
  7. Create four buttons.
  8. Set the name for each button according to its function: (addButton, subButton, multButton, or divButton) [The tests need you to use the setName method on the buttons. The names of your variables don't matter.]
  9. Add the buttons to the button panel.
  10. Add the button panel to the frame.
  11. Create a result panel.
  12. Create a result label.
  13. Set the name of the result label to resultLabel. [Use the setName method again.]
  14. Add the result label to the result panel.
  15. Add the result panel to the frame.
  16. Create a text field panel.
  17. Create two text fields.
  18. Set the name of each text field according to its contents: (leftOperand or rightOperand). [Use the setName method again.]
  19. Add both text fields to the text field panel.
  20. Add the text field panel to the frame.
  21. Add the button handler inner classes.
  22. Make the buttons work.
    1. Remember buttons need a listener.
    2. If the user leaves a field blank the calculator label should say "Result = Error".
    3. If the user enters a non-number, the calculator should say "Result = Error".
    4. Hint: Double.parseDouble(String t) will get a double out of a String, but be weary because it can throw a NumberFormatException.
    5. Hint: Don't forget that you can't divide by zero!

Java Create a New Class: Right-click your project (Lab04) and Select New-->Class

0 My Simple Calculator 54 32 Result = 86 ADD SUB MULT DIV The calculator after an error. My Simple Calculator 0 34 Result = Error ADD SUB MULT DIV

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!