LAB PROJECT 1: Java GUI- BMI Calculator

Goal: In this project exercise, you will learn how to:
1. Install the Java Eclipse Windows Builder software
2. Create a Java GUI application using the JFrame Library Classes.
3. Use an Absolute Layout to construct the content Pane of the GUI window
4. Add JLabel, JTextBox and JButton components to the content Pane
5. Add the Event Code to the JButton
6. Declare the Variables
7. Use a Try Catch Block to perform input error handling.

Program Specifications:
Create a Java GUI program that will calculate the Body Mass Index (BMI) of a patient.  Store and assign the data - patient name, age, height (inches) and weight (pounds) in variables.  Display the patient’s BMI results on the screen. The formula of the BMI in Standard measurements is:

BMI = (weight / (height * height)) *703

Pre-requisites:
1. Create a folder on your desktop Project-1

2. Launch Java EE- Eclipse
Note:  You will need to use the Java Perspective Workbench for this exercise

3. Setup your Eclipse Workspace to point to the Project-1 folder
a. Select File-> Switch Workspace
b. Browse and select your Project-1 folder as your Workspace.




Software Installation Pre-requisites:
     You will need to have install the Java Eclipse Windows Builder. 
     NOTE:  In the LMC Computer Lab, this already has been installed.
1.  Select Help-> Install New Software

2.  a. Copy and paste the link below in the Work with box.

         WindowsBuilder - http://download.eclipse.org/windowbuilder/lastgoodbuild/

     b. Select All
     c. Click Next and complete the installation.

      

NOTE:   Attached is the WindowsBuilder repository components in case installation steps above does not work
Repository Link

Requirements:

1.   Create a Java Project and name it as BMICalculatorGUI

2.   Right click on the src folder.  Select New-> Other

       

3.   Scroll down.  Expand the Windows Builder folder. 
 Select JFrame and click Next

           

4.  Type MainApp as the name for the JFrame.  Click on the Finish button.

 

Requirements for the MainApp Class:
A.  Create the JFrame Components

1.  Click on the Design tab

2.  a. Click on the Frame
     b. Set the resizable property to “false”. Uncheck box
     c. Add the title property “BMI Calculator”

d. Click inside the frame container.   Note:  You will see the square corner handles

       

3.  Create the Layout
 a.
Select the Absolute Layout
 
b.
Click inside the container to create the Absolute Layout



4.  Verify the Layout is set to “Absolute”
a.  Click inside the container
b.  In the Properties panel, Layout should have the “absolute” value
     NOTE:  If not, select the value from the pull down arrow
c.  Verify that you are in the contentPane

5.   Create the Labels

a.   Select JLabel and drag the component into the content pane.

b.   Enter the text name of the label (see list below).  Resize the label by using the handles
 Resize the label by using the corner handles
 Position the label on the screen

c.   In the Properties panel, set the Font size to 20
  Note:  Create all of the 3 Labels and name them as follows:
            Height
            Weight
            BMI

6.   Create the Text Field boxes
a. Select JTextField and drag the component into the content pane.
b. Select to highlight the TextField box.  Resize the text box by using the handles
c. In the Properties Panel under Variable, name the text box (see list below)
d. Set the Font size to 20 
Note:  Create all of the 4 Text Field Boxes and name them as follows: 
           Verify the text box names are correctly entered.
            textFeet
            textInches
            textWeight
            textBMI

7.  Add the Additional Labels

a.   Select JLabel and drag the component into the content pane.

b.   Enter the text name of the label.   Resize the label by using the handles
 Resize the label by using the corner handles
 Position the label on the screen

c.   In the Properties panel, set the Font size to 15
Note:  Create all of the 3 additional labels and name as follows:
            feet
            inches
            pounds

            

8.  Create the Buttons

a.   Select JButton and drag the component into the content pane.

b.   In the Properties Panel under Variable, enter the variable name (see below).

c.   Set the Font Size (see below).

d.   Enter the Text that will be displayed inside the button. Resize the button by using the handles
 Note:  Create all of the 3 buttons and name as follows
           Verify the variables names are correctly entered.
Variable Name:      Font Size       Text:
btnCalculateBMI    16 Bold            Compute BMI
btnClear                   14                   Clear

 btnExit                     14                    Exit

           

 

B.  Add the Event Code for the btnCalculateBMI button
  
1.  Right click on the button
   2.  Select Add event handler -> action ->   actionPerformed
        

3. Below is the event code to add in the void method actionPerformed for the btnCalculateBMI button.
    NOTE: You will need to be in Source tab section to add the event code.
   

       

  4.  At the top of the source code before the MainApp class, add the following:
       a.  import javax.swing.JOptionPane;    (Note: This is used for the Show Message Dialog box)
       b. @SuppressWarnings("serial")
      

 

C.  Add the Event Code for the btnClear button

1.  Right click on the button
2.  Select Add event handler -> action ->   actionPerformed    



3.  Below is the code to add in the void method actionPerformed for the btnClear button.
     NOTE: You will need to be in Source tab section to add the event code.
    

   

 

D.  Add the Event Code for the btnExit button
1.  Right click on the button
2.  Select Add event handler -> action ->   actionPerformed     

3. Below is the code to add in the void method actionPerformed for the btnExit button.
    NOTE: You will need to be in Source tab section to add the event code.
    

  

 

Test:  

1.   Save your Java code

2.   Compile and run your Java program.

3.   Verify there is no syntax, logical or run-time errors.

4.   Enter the following test data.
Height   5 ft  8 in
Weight 180  lbs

Submit:

1.  REQUIREMENT:  You will need to submit a screenshot of the JFrame Main App Design Mode in Project-01 Folder to receive points on this project

2.  Zip up (compress) the Project-01 folder

3.  Upload the zip folder to the Desire2Learn Java GUI  Project’s Project-01 drop box.