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

Build a Quiz Game Using HTML CSS and JavaScript Introduction Hello coders, you might have played various games, but were you aware …

Emoji Catcher Game Using HTML CSS and JavaScript Introduction Hello Coders, Welcome to another new blog. In this article we’ve made a …

Typing Challenge Using HTML CSS and JavaScript Introduction Hello friends, all you developer friends are welcome to our new project. If you …

Breakout Game Using HTML CSS and JavaScript With Source Code Introduction Hello friends, welcome to today’s new blog post. All of you …

Digital and Analog Clock using HTML CSS and JavaScript Introduction : This project is a digital clock and stopwatch system, which allows …

Coffee Shop Website using HTML, CSS & JavaScript Introduction : This project is a website for coffee house business. It uses HTML …