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
PlotterPanel.java
src/main/java/com/rskworld/mathtools/panels/PlotterPanel.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.ThemeManager;
import javax.swing.*;
import java.awt.*;

public class PlotterPanel extends JPanel {
    private JTextField aField, bField, cField;
    private GraphCanvas canvas;

    public PlotterPanel() {
        setLayout(new BorderLayout(10, 10));
        setBackground(ThemeManager.BACKGROUND);
        setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        initComponents();
    }

    private void initComponents() {
        JPanel control = new JPanel(new FlowLayout());
        control.setOpaque(false);
        control.add(new JLabel("y = "));
        aField = new JTextField("1", 3);
        control.add(aField);
        control.add(new JLabel("x² + "));
        bField = new JTextField("0", 3);
        control.add(bField);
        control.add(new JLabel("x + "));
        cField = new JTextField("0", 3);
        control.add(cField);

        JButton plotBtn = new JButton("Plot Graph");
        plotBtn.addActionListener(e -> canvas.repaint());
        control.add(plotBtn);

        add(control, BorderLayout.NORTH);

        canvas = new GraphCanvas();
        add(canvas, BorderLayout.CENTER);

        ThemeManager.applyTheme(this);
    }

    private class GraphCanvas extends JPanel {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            
            int w = getWidth();
            int h = getHeight();
            int centerX = w / 2;
            int centerY = h / 2;
            int scale = 20;

            // Draw Axis
            g2.setColor(Color.GRAY);
            g2.drawLine(0, centerY, w, centerY);
            g2.drawLine(centerX, 0, centerX, h);

            // Draw Parabola
            try {
                double a = Double.parseDouble(aField.getText());
                double b = Double.parseDouble(bField.getText());
                double c = Double.parseDouble(cField.getText());

                g2.setColor(ThemeManager.ACCENT_RED);
                g2.setStroke(new BasicStroke(2));

                int prevX = -1, prevY = -1;
                for (int screenX = 0; screenX < w; screenX++) {
                    double x = (double) (screenX - centerX) / scale;
                    double y = a * x * x + b * x + c;
                    int screenY = centerY - (int) (y * scale);

                    if (prevX != -1 && screenY >= 0 && screenY <= h) {
                        g2.drawLine(prevX, prevY, screenX, screenY);
                    }
                    prevX = screenX;
                    prevY = screenY;
                }
            } catch (Exception e) {}
        }
    }
}
94 lines•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