11/*
22Name: Four.
3- Date: Apr 16 2024.
3+ Date: originally written on Apr 16 2024.
44Class: CS 145.
55Assignment: Lab 2: Target Heart Rate.
6- Purpose: Creates an application where a user can input info and receive data about their target heart rate.
6+ Purpose: Creates an application where a user can input info and receive data about their target heart rate,
7+ based on data from the American Heart Association.
78
89WARNING: I MADE THIS PROGRAM WITH JDK VERSION 22. I CANNOT GUARANTEE IT WILL WORK WITH EARLIER VERSIONS.
910 */
1011import javax .swing .*;
11- //awt for the button
12+ // AWT for the button
1213import java .awt .*;
1314import java .awt .event .*;
1415
15- //I'm still learning how to use Swing.
16- //but from what I know, this extends the JFrame class to create our own custom "frame" or window,
17- //then we just need to set certain parameters.
16+ // I'm still learning how to use Swing.
17+ // but from what I know, this extends the JFrame class to create our own custom "frame" or window,
18+ // then we just need to set certain parameters.
1819public class HeartRateGUI extends JFrame {
1920 private JTextField firstNameField ;
2021 private JTextField lastNameField ;
@@ -23,22 +24,22 @@ public class HeartRateGUI extends JFrame {
2324 private JTextField birthYearField ;
2425
2526 public static void main (String [] args ) {
26- //I know you said keep main as small as possible, but this is a little silly.
27- //this creates a new window for the HeartRateGUI.
27+ // Creates an object to run the program
2828 new HeartRateGUI ();
2929 }
3030
3131 // Creates the window.
3232 public HeartRateGUI () {
33- //the name of the window
33+ // The name of the window
3434 super ("Heart Rate Calculator" );
3535 initComponents ();
36+ // 6 rows, 2 cols
3637 setLayout (new GridLayout (6 , 2 ));
3738 addComponents ();
3839 setVisible (true );
3940 }
4041
41- //initiates components for the window, such as fields (text boxes) and the size.
42+ // Initiates components for the window, such as fields (text boxes) and the size.
4243 private void initComponents () {
4344 setSize (400 , 300 );
4445 setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
@@ -51,7 +52,7 @@ private void initComponents() {
5152 birthYearField = new JTextField ();
5253 }
5354
54- //actually put the components we just initialized onto the window.
55+ // Actually put the components we just initialized onto the window.
5556 private void addComponents () {
5657 // Add labels and fields
5758 add (new JLabel ("First Name:" ));
@@ -69,8 +70,8 @@ private void addComponents() {
6970 JButton calculateButton = new JButton ("Calculate" );
7071 calculateButton .addActionListener (new ActionListener () {
7172 public void actionPerformed (ActionEvent e ) {
72- //when the button is clicked, calculate the heart rate.
73- //and pass in everything it needs.
73+ // When the button is clicked, calculate the heart rate.
74+ // And pass in everything it needs.
7475 HeartRateCalculator .calculateHeartRate (
7576 firstNameField .getText (),
7677 lastNameField .getText (),
@@ -84,13 +85,13 @@ public void actionPerformed(ActionEvent e) {
8485 add (calculateButton );
8586 }
8687
87- //is called from the calculator to open a pane for the final heart rate info
88+ // Is called from the calculator to open a pane for the final heart rate info
8889 public void displayHeartRateInfo (String info ) {
8990 JOptionPane .showMessageDialog (this , info , "Heart Rate Information" ,
9091 JOptionPane .INFORMATION_MESSAGE );
9192 }
9293
93- //is called from the calculator to send an error message.
94+ // Is called from the calculator to send an error message.
9495 public void displayErrorMessage (String message ) {
9596 JOptionPane .showMessageDialog (this , message , "Error" ,
9697 JOptionPane .ERROR_MESSAGE );
0 commit comments