help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
java-math-tools
/
src
/
main
/
java
/
com
/
rskworld
/
mathtools
/
panels
RSK World
java-math-tools
Java Math Tools - 15 Mathematical Tools + Scientific Calculator + Geometry + Statistics + Financial Calculators + Swing GUI + Educational Design
panels
  • AgeCalculatorPanel.java2.4 KB
  • BMIPanel.java2.3 KB
  • CalculatorPanel.java4.5 KB
  • ConstantsPanel.java1.6 KB
  • EquationSolverPanel.java3.3 KB
  • FinancialPanel.java3.2 KB
  • GSTPanel.java2.1 KB
  • GeometryPanel.java4 KB
  • HistoryPanel.java1.8 KB
  • MatrixPanel.java4.2 KB
  • NumberSystemPanel.java3 KB
  • PasswordPanel.java3.2 KB
  • PlotterPanel.java3 KB
  • PrimePanel.java3.5 KB
  • StatisticsPanel.java3.5 KB
  • UnitConverterPanel.java5.8 KB
EquationSolverPanel.java
src/main/java/com/rskworld/mathtools/panels/EquationSolverPanel.java
Raw Download
Find: Go to:
/**
 * Project: Java Basic Math Tools
 * Developer: Molla Samser
 * Designer & Tester: Rima Khatun
 * Website: https://rskworld.in
 * Year: 2026
 */

package com.rskworld.mathtools.panels;

import com.rskworld.mathtools.utils.HistoryManager;
import com.rskworld.mathtools.utils.ThemeManager;
import javax.swing.*;
import java.awt.*;

public class EquationSolverPanel extends JPanel {
    private JTextField aField, bField, cField, resultArea;

    public EquationSolverPanel() {
        setLayout(new BorderLayout(10, 10));
        setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        initComponents();
    }

    private void initComponents() {
        JPanel inputPanel = new JPanel(new GridLayout(4, 2, 5, 5));
        inputPanel.setBorder(BorderFactory.createTitledBorder("Quadratic Equation: ax² + bx + c = 0"));

        inputPanel.add(new JLabel("Value of a:"));
        aField = new JTextField();
        inputPanel.add(aField);

        inputPanel.add(new JLabel("Value of b:"));
        bField = new JTextField();
        inputPanel.add(bField);

        inputPanel.add(new JLabel("Value of c:"));
        cField = new JTextField();
        inputPanel.add(cField);

        JButton solveBtn = new JButton("Solve Equation");
        solveBtn.addActionListener(e -> solveQuadratic());
        inputPanel.add(solveBtn);

        add(inputPanel, BorderLayout.NORTH);

        resultArea = new JTextField();
        resultArea.setEditable(false);
        resultArea.setFont(new Font("Monospaced", Font.BOLD, 16));
        resultArea.setBorder(BorderFactory.createTitledBorder("Result"));
        add(resultArea, BorderLayout.CENTER);
        ThemeManager.applyTheme(this);
    }

    private void solveQuadratic() {
        try {
            double a = Double.parseDouble(aField.getText());
            double b = Double.parseDouble(bField.getText());
            double c = Double.parseDouble(cField.getText());

            if (a == 0) {
                // Linear equation: bx + c = 0
                if (b == 0) {
                    resultArea.setText(c == 0 ? "Infinite solutions" : "No solution");
                } else {
                    resultArea.setText("Linear Root: x = " + (-c / b));
                }
                return;
            }

            double discriminant = b * b - 4 * a * c;
            if (discriminant > 0) {
                double r1 = (-b + Math.sqrt(discriminant)) / (2 * a);
                double r2 = (-b - Math.sqrt(discriminant)) / (2 * a);
                resultArea.setText(String.format("Two real roots: x1 = %.2f, x2 = %.2f", r1, r2));
            } else if (discriminant == 0) {
                double r = -b / (2 * a);
                resultArea.setText(String.format("One real root: x = %.2f", r));
            } else {
                double realPart = -b / (2 * a);
                double imagPart = Math.sqrt(-discriminant) / (2 * a);
                resultArea.setText(String.format("Complex roots: %.2f ± %.2fi", realPart, imagPart));
            }
            HistoryManager.getInstance().addEntry("Solved Quadratic: " + a + "x^2 + " + b + "x + " + c + " = 0 -> " + resultArea.getText());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Please enter valid numbers");
        }
    }
}
90 lines•3.3 KB
java

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer