Fitness Tracker App Using Java Swing

Introduction:

The Health and Fitness Tracker is a Java GUI application designed to assist users in monitoring their daily physical activities and maintaining a healthy lifestyle. This application allows users to track important fitness metrics such as steps taken, distance covered, and calories burned. By offering an intuitive graphical interface, users can easily input and visualize their progress over time, helping them stay motivated and focused on their fitness goals.

Key Features:

  1. User Profile: Users can create personalized profiles by entering their basic information such as age, gender, weight, and height. This information is used to calculate accurate calorie burn estimates.

  2. Activity Tracking: The application enables users to input their daily activities, including the number of steps taken and distance covered. Users can also record different types of physical exercises they engage in.

  3. Calories Burned Calculation: The application calculates an estimate of calories burned based on the user’s profile and the input activity data. This helps users understand the impact of their activities on their overall health.

  4. Progress Visualization: The app provides graphical representations of the user’s daily, weekly, and monthly progress. This includes visualizations of steps, distance, and calories burned, helping users track trends and set new goals.

  5. Goal Setting: Users can set fitness goals, such as a target number of steps or calories burned per day. The application provides notifications and visual indicators to motivate users to reach their goals.

  6. Data Storage: The application stores activity data and user profiles, allowing users to review their historical data and analyze their long-term progress.

Source Code:

				
					import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class FitnessTrackerApp extends JFrame {
    private JTextField stepsField;
    private JTextField distanceField;
    private JButton trackButton;
    private JLabel resultLabel;

    public FitnessTrackerApp() {
        setTitle("Health and Fitness Tracker");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300, 200);

        stepsField = new JTextField(10);
        distanceField = new JTextField(10);
        trackButton = new JButton("Track Activity");
        resultLabel = new JLabel();

        trackButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int steps = Integer.parseInt(stepsField.getText());
                double distance = Double.parseDouble(distanceField.getText());
                
                // Perform calculations to estimate calories burned
                double caloriesBurned = calculateCaloriesBurned(steps, distance);
                
                // Display the results to the user
                resultLabel.setText("Calories Burned: " + caloriesBurned);
            }
        });

        JPanel inputPanel = new JPanel(new GridLayout(3, 2));
        inputPanel.add(new JLabel("Steps taken:"));
        inputPanel.add(stepsField);
        inputPanel.add(new JLabel("Distance (km):"));
        inputPanel.add(distanceField);
        inputPanel.add(new JLabel());
        inputPanel.add(trackButton);

        JPanel resultPanel = new JPanel();
        resultPanel.add(resultLabel);

        add(inputPanel, BorderLayout.CENTER);
        add(resultPanel, BorderLayout.SOUTH);
    }

    // Method to calculate estimated calories burned
    private double calculateCaloriesBurned(int steps, double distance) {
        // Simplified calculation; you can implement a more accurate formula
        double caloriesPerStep = 0.04; // Sample value, modify accordingly
        double caloriesPerDistance = 0.1; // Sample value, modify accordingly
        
        return (steps * caloriesPerStep) + (distance * caloriesPerDistance);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new FitnessTrackerApp().setVisible(true);
            }
        });
    }
}

				
			

Output:

Find More Projects

Complain Management using Python with a Graphical User Interface (GUI) Introduction: The Complain Management using Python program designed to manage complaints effectively …

COVID 19 Hospital Management Using Python [Django Framework] Introduction: The COVID-19 Hospital Management is a Python-based application that tracks web applications for Hospitals. …

Drawing Ganesha Using Python Turtle Graphics[Drawing Ganapati Using Python] Introduction In this blog post, we will learn how to draw Lord Ganesha …

Contact Management System in Python with a Graphical User Interface (GUI) Introduction: The Contact Management System is a Python-based application designed to …

KBC Game using Python with Source Code Introduction : Welcome to this blog post on building a “Kaun Banega Crorepati” (KBC) game …

Basic Logging System in C++ With Source Code Introduction : It is one of the most important practices in software development. Logging …