πŸ’° Java Swing Personal Finance Tracker App – Modern GUI Budget Manager

Demo :


Click Video πŸ‘‡πŸ‘‡πŸ‘‡
















πŸ”₯ Features :

Modern Java Swing GUI
Income & Expense Tracking
Balance Calculation in Real-Time
Dark & Light Mode for Better UX
Download Full Source Code
YouTube Video Link Embedded for Demo


Code :


import javax.swing.*;

import javax.swing.table.DefaultTableModel;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


public class FinanceTracker extends JFrame {

    private DefaultTableModel model;

    private JTable table;

    private JTextField amountField, categoryField;

    private JLabel balanceLabel;

    private double balance = 0;

    

    public FinanceTracker() {

        setTitle("Personal Finance Tracker");

        setSize(500, 400);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setLocationRelativeTo(null);


        JPanel panel = new JPanel();

        panel.setLayout(new BorderLayout());


        // Table setup

        model = new DefaultTableModel(new String[]{"Category", "Amount"}, 0);

        table = new JTable(model);

        JScrollPane scrollPane = new JScrollPane(table);

        panel.add(scrollPane, BorderLayout.CENTER);


        // Input Fields

        JPanel inputPanel = new JPanel();

        inputPanel.setLayout(new GridLayout(3, 2, 5, 5));

        inputPanel.add(new JLabel("Category:"));

        categoryField = new JTextField();

        inputPanel.add(categoryField);

        inputPanel.add(new JLabel("Amount:"));

        amountField = new JTextField();

        inputPanel.add(amountField);

        JButton addButton = new JButton("Add Transaction");

        inputPanel.add(addButton);

        panel.add(inputPanel, BorderLayout.NORTH);


        // Balance Label

        balanceLabel = new JLabel("Balance: $0.00", SwingConstants.CENTER);

        balanceLabel.setFont(new Font("Arial", Font.BOLD, 16));

        panel.add(balanceLabel, BorderLayout.SOUTH);


        // Add Button Action

        addButton.addActionListener(new ActionListener() {

            @Override

            public void actionPerformed(ActionEvent e) {

                addTransaction();

            }

        });


        add(panel);

    }


    private void addTransaction() {

        String category = categoryField.getText();

        String amountText = amountField.getText();

        

        try {

            double amount = Double.parseDouble(amountText);

            balance += amount;

            model.addRow(new Object[]{category, "$" + amountText});

            balanceLabel.setText("Balance: $" + String.format("%.2f", balance));

            categoryField.setText("");

            amountField.setText("");

        } catch (NumberFormatException e) {

            JOptionPane.showMessageDialog(this, "Please enter a valid number", "Error", JOptionPane.ERROR_MESSAGE);

        }

    }


    public static void main(String[] args) {

        SwingUtilities.invokeLater(() -> {

            FinanceTracker app = new FinanceTracker();

            app.setVisible(true);

        });

    }

}

Comments

Popular posts from this blog

πŸš€ Simple Login & Registration System in Python Tkinter πŸ“±

πŸš€ Create a Python Screen Recorder with Audio (Complete Code)

πŸ“‘ Fuzzu Packet Sniffer – Python GUI for Real-Time IP Monitoring | Tkinter + Scapy