Lab: Natural Number Calculator View


We recommend that you work on this lab with a classmate. Any work you and your partner develop during the lab can be shared in your project submission. However, after the lab is concluded, each student is required to work on the remainder of the project on their own.

Objective

In this lab you will design and implement a GUI for a NaturalNumber calculator that may be used in your Natural Number Calculator project.

Setup

Follow these steps to set up a project for this lab.

  1. Create a new Eclipse project by copying ProjectTemplate. Name the new project NaturalNumberCalculatorView.
  2. Open the src folder of this project and then open (default package). As a starting point you can use any of the Java files. Rename it NNCalcViewLab and delete the other files from the project.
  3. Follow the link to NNCalcViewLab.java, select all the code on that page and copy it to the clipboard; then open the NNCalcViewLab.java file in Eclipse and paste the code to replace the file contents. Save your file.

Method

  1. First carefully look through the NNCalcViewLab.java. The skeleton provides the following:
  2. Complete the constructor to build a GUI for the calculator. This is the suggested layout for the GUI:

  3. Run the program and modify your interface until it looks "just right".

Calculator Demo

A demo version of an executable solution to the calculator project is provided for you to experiment with and possibly to emulate. The user interface in your solution is not required to match the one in the demo, but it may be easier to try to reproduce the GUI of the demo at least as a starting point.

To run the demo, you need to import the program into Eclipse. First you need to download the project archive, natural-number-calculator.zip, to your computer. Click on this download link and save the file somewhere on your hard drive where you can easily find it. Make sure that you do not expand this archive. If your browser automatically expands downloaded zip archives, that's OK too. Just pay attention to the special instructions in the following few steps. You may want to make a note of where you saved it.

Import your new project in Eclipse by following these steps:

  1. From the File menu select Import....
  2. In the new window, expand General and select Existing Projects into Workspace. Click Next.
  3. Click on the radio button next to Select archive file and then click the Browse... button. (If the archive was expanded when you downloaded the file to your own computer, click on Select root directory... instead.)
  4. In the file selection window, find the natural-number-calculator.zip file and select it. (If your browser expanded the archive, find the natural-number-calculator directory instead.) Click OK.
  5. Click Finish.

To run the program, find the RunCalculator.java file in the src folder in the project and run it as usual as a Java Application.

Additional Activities

  1. If you complete your GUI design with time to spare, you should get started with the Natural Number Calculator project. Review the skeleton class NNCalcView1 provided with the project and complete the constructor to build the GUI for the calculator. Note that there are a few additional elements in NNCalcView1.java that were not included in this lab.