Plotting equations on a cartesian Plane

Plotting equations on a cartesian Plane

Hey, Im sort of a beginner of java, and i at the moment of working on a program that takes the input of an equation (eg. y=3x) and plots possible values for it on a cartesian plane thats on a seperate JPanel.

Here is my code: This is Class 1

import java.awt.Color;
import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Graphs extends JFrame implements KeyListener
{
    GraphingPanel p = new GraphingPanel();
    JPanel[] Panel = new JPanel[2];
    JLabel[] Label = new JLabel[100];
    JTextField[] Field = new JTextField[100];
    JButton[] Enter = new JButton[100];
    JButton[] Clear = new JButton[100];
    JComboBox Subjects = new JComboBox();
    JComboBox Topics = new JComboBox();

    public Graphs()
    {
        super();
        setSize(600, 500);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setUndecorated(true);
        setLocationRelativeTo(null);
        LoadUI();
    }

    public void LoadUI()
    {
        Field[0] = new JTextField();
        Panel[0] = new JPanel(null);
        Panel[1] = p;


        Field[0].setBounds(240, 20, 120, 30);
        Field[0].addKeyListener(this);

        Panel[0].add(Field[0]);
        Panel[0].add(Panel[1]);
        add(Panel[0]);
        setVisible(true);
    }

    public static void main(String[] args)
    {
        Graphs Main = new Graphs();
    }

    @Override
    public void keyPressed(KeyEvent e)
    {
        if(e.getKeyCode()==10)
        {
            String str = Field[0].getText();
            DrawGraph g = new DrawGraph(str);
        }
    }

    @Override
    public void keyReleased(KeyEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void keyTyped(KeyEvent arg0) {
        // TODO Auto-generated method stub

    }
}

The Second Class:

import java.awt.*;
import java.awt.geom.*;

import javax.swing.*;

public class GraphingPanel extends JPanel
{
    public GraphingPanel()
    {
        setBounds(50, 50, 500, 400);
        setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        setBackground(Color.WHITE);
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponents(g);

        int panelWidth = getWidth();
        int panelHeight = getHeight();

        g.setColor(Color.WHITE);
        g.fillRect(0, 0, panelWidth, panelHeight);
        g.setColor(Color.BLACK);

        Graphics2D g2 = (Graphics2D) g;
        g2.setStroke(new BasicStroke(1f));


        g2.draw(new Line2D.Double( 0, panelHeight/2, panelWidth ,panelHeight/2 ));
        g2.draw(new Line2D.Double(panelWidth/2,0, panelWidth/2 ,panelHeight));
        g2.setFont(new Font("Times New Roman", Font.PLAIN, 13));

        for(int i=1;i<getWidth();i+=9)
        {
            g2.draw(new Line2D.Double(i, (getHeight()/2)-2, i, (getHeight()/2)+2));
        }

        for(int i=1;i<getHeight();i+=9)
        {
            g2.draw(new Line2D.Double((getWidth()/2)-2, i,(getWidth()/2)+2,i));
        }
    }
}

Im just struggling to figure out how to plot a line graph after the user has input his equation into the Text field.. Your help will be greatly appreciated:)

View Answers









Related Tutorials/Questions & Answers:
Plotting equations on a cartesian Plane
Plotting equations on a cartesian Plane  Hey, Im sort of a beginner of java, and i at the moment of working on a program that takes the input of an equation (eg. y=3x) and plots possible values for it on a cartesian plane thats
ModuleNotFoundError: No module named 'cartesian'
ModuleNotFoundError: No module named 'cartesian'  Hi, My Python... 'cartesian' How to remove the ModuleNotFoundError: No module named 'cartesian' error? Thanks   Hi, In your python environment you
Advertisements
What is a Cartesian product?
What is a Cartesian product?   What is a Cartesian product?   Hi, Here is the answer,ADS_TO_REPLACE_1 The Cartesian product, also.... Both the EMPLOYEE and STORE tables have 5 rows. If we use a Cartesian join
ModuleNotFoundError: No module named 'plotting'
ModuleNotFoundError: No module named 'plotting'  Hi, My Python... 'plotting' How to remove the ModuleNotFoundError: No module named 'plotting... to install padas library. You can install plotting python with following
ModuleNotFoundError: No module named 'equations'
ModuleNotFoundError: No module named 'equations'  Hi, My Python... 'equations' How to remove the ModuleNotFoundError: No module named 'equations' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'equations'
ModuleNotFoundError: No module named 'equations'  Hi, My Python... 'equations' How to remove the ModuleNotFoundError: No module named 'equations' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'plane'
ModuleNotFoundError: No module named 'plane'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'plane' How to remove the ModuleNotFoundError: No module named 'plane'
ModuleNotFoundError: No module named 'plane-a'
ModuleNotFoundError: No module named 'plane-a'  Hi, My Python... 'plane-a' How to remove the ModuleNotFoundError: No module named 'plane... to install padas library. You can install plane-a python with following command
ModuleNotFoundError: No module named 'outlier-plotting'
ModuleNotFoundError: No module named 'outlier-plotting'  Hi, My... named 'outlier-plotting' How to remove the ModuleNotFoundError: No module named 'outlier-plotting' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'unified-plotting'
ModuleNotFoundError: No module named 'unified-plotting'  Hi, My... named 'unified-plotting' How to remove the ModuleNotFoundError: No module named 'unified-plotting' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'backtrader-plotting'
ModuleNotFoundError: No module named 'backtrader-plotting'  Hi, My... named 'backtrader-plotting' How to remove the ModuleNotFoundError: No module named 'backtrader-plotting' error? Thanks   Hi
plotting a graph - Java Beginners
plotting a graph  pls help me out regarding plotting a graph. I have done that through LiveGraph API. but now i required the graph to be displayed on the gui- window. and whatever inputs i will pass it must change the graph
place reservation in plane
place reservation in plane   hi,how can i write a program in Java programming to place reservation in air plane from the menu let the user to inter his/her name, age, date of traveling, and the seat in the plane
plotting of points inside a rectangle
plotting of points inside a rectangle  I want to plot various points inside a rectangle such that any two points are at a distance of at least 3 units from each other. I want all possible configurations that are possible.For
reservation of seat in plane
reservation of seat in plane  hi,how can i write a program in Java programming to place reservation in air plane from the menu let the user to inter his/her name, age, date of traveling, and the seat in the plane
Version of com.kasonchan>equations-massbalance_2.11 dependency
List of Version of com.kasonchan>equations-massbalance_2.11 dependency
Version of com.kasonchan>equations-monooperation_2.11 dependency
List of Version of com.kasonchan>equations-monooperation_2.11 dependency
ModuleNotFoundError: No module named 'ljy-plane'
ModuleNotFoundError: No module named 'ljy-plane'  Hi, My Python... 'ljy-plane' How to remove the ModuleNotFoundError: No module named 'ljy-plane' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'ming-plane'
ModuleNotFoundError: No module named 'ming-plane'  Hi, My Python... 'ming-plane' How to remove the ModuleNotFoundError: No module named 'ming-plane' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'plane-feiji'
ModuleNotFoundError: No module named 'plane-feiji'  Hi, My Python... 'plane-feiji' How to remove the ModuleNotFoundError: No module named 'plane-feiji' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'plane-fight'
ModuleNotFoundError: No module named 'plane-fight'  Hi, My Python... 'plane-fight' How to remove the ModuleNotFoundError: No module named 'plane-fight' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'plane-frighting'
ModuleNotFoundError: No module named 'plane-frighting'  Hi, My... named 'plane-frighting' How to remove the ModuleNotFoundError: No module named 'plane-frighting' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'plane-fx'
ModuleNotFoundError: No module named 'plane-fx'  Hi, My Python... 'plane-fx' How to remove the ModuleNotFoundError: No module named 'plane-fx... to install padas library. You can install plane-fx python with following
ModuleNotFoundError: No module named 'plane-fxx'
ModuleNotFoundError: No module named 'plane-fxx'  Hi, My Python... 'plane-fxx' How to remove the ModuleNotFoundError: No module named 'plane... have to install padas library. You can install plane-fxx python with following
ModuleNotFoundError: No module named 'plane-war'
ModuleNotFoundError: No module named 'plane-war'  Hi, My Python... 'plane-war' How to remove the ModuleNotFoundError: No module named 'plane... have to install padas library. You can install plane-war python with following
ModuleNotFoundError: No module named 'snakes-on-a-plane'
ModuleNotFoundError: No module named 'snakes-on-a-plane'  Hi, My... named 'snakes-on-a-plane' How to remove the ModuleNotFoundError: No module named 'snakes-on-a-plane' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'fight-plane'
ModuleNotFoundError: No module named 'fight-plane'  Hi, My Python... 'fight-plane' How to remove the ModuleNotFoundError: No module named 'fight-plane' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'qcb-plotting-tools'
ModuleNotFoundError: No module named 'qcb-plotting-tools'  Hi, My... named 'qcb-plotting-tools' How to remove the ModuleNotFoundError: No module named 'qcb-plotting-tools' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'elsa-plotting-wand'
ModuleNotFoundError: No module named 'elsa-plotting-wand'  Hi, My... named 'elsa-plotting-wand' How to remove the ModuleNotFoundError: No module named 'elsa-plotting-wand' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'python-category-equations'
ModuleNotFoundError: No module named 'python-category-equations'  Hi...: No module named 'python-category-equations' How to remove the ModuleNotFoundError: No module named 'python-category-equations' error? Thanks  
ModuleNotFoundError: No module named 'python-category-equations'
ModuleNotFoundError: No module named 'python-category-equations'  Hi...: No module named 'python-category-equations' How to remove the ModuleNotFoundError: No module named 'python-category-equations' error? Thanks  
ModuleNotFoundError: No module named 'python-domain-equations'
ModuleNotFoundError: No module named 'python-domain-equations'  Hi...: No module named 'python-domain-equations' How to remove the ModuleNotFoundError: No module named 'python-domain-equations' error? Thanks   
ModuleNotFoundError: No module named 'damo-Plane-Wars'
ModuleNotFoundError: No module named 'damo-Plane-Wars'  Hi, My... named 'damo-Plane-Wars' How to remove the ModuleNotFoundError: No module named 'damo-Plane-Wars' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'damo-Plane-Wars'
ModuleNotFoundError: No module named 'damo-Plane-Wars'  Hi, My... named 'damo-Plane-Wars' How to remove the ModuleNotFoundError: No module named 'damo-Plane-Wars' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'lss-plane-war'
ModuleNotFoundError: No module named 'lss-plane-war'  Hi, My... 'lss-plane-war' How to remove the ModuleNotFoundError: No module named 'lss-plane-war' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'lss-plane-war'
ModuleNotFoundError: No module named 'lss-plane-war'  Hi, My... 'lss-plane-war' How to remove the ModuleNotFoundError: No module named 'lss-plane-war' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'reaction-plane-fit'
ModuleNotFoundError: No module named 'reaction-plane-fit'  Hi, My... named 'reaction-plane-fit' How to remove the ModuleNotFoundError: No module named 'reaction-plane-fit' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'snmpsim-control-plane'
ModuleNotFoundError: No module named 'snmpsim-control-plane'  Hi...: No module named 'snmpsim-control-plane' How to remove the ModuleNotFoundError: No module named 'snmpsim-control-plane' error? Thanks   Hi
ModuleNotFoundError: No module named 'damo-Plane-Wars'
ModuleNotFoundError: No module named 'damo-Plane-Wars'  Hi, My... named 'damo-Plane-Wars' How to remove the ModuleNotFoundError: No module named 'damo-Plane-Wars' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'envoy-data-plane'
ModuleNotFoundError: No module named 'envoy-data-plane'  Hi, My... named 'envoy-data-plane' How to remove the ModuleNotFoundError: No module named 'envoy-data-plane' error? Thanks   Hi, In your
Maven Dependency equations-massbalance_2.11 >> 0.1.0
You should include the dependency code given in this page to add Maven Dependency of com.kasonchan >> equations-massbalance_2.11 version0.1.0 in your project
Maven Dependency equations-massbalance_2.11 >> 0.1.1
You should include the dependency code given in this page to add Maven Dependency of com.kasonchan >> equations-massbalance_2.11 version0.1.1 in your project
Maven Dependency equations-monooperation_2.11 >> 0.1.0
You should include the dependency code given in this page to add Maven Dependency of com.kasonchan >> equations-monooperation_2.11 version0.1.0 in your project
Maven Dependency equations-monooperation_2.11 >> 0.1.1
You should include the dependency code given in this page to add Maven Dependency of com.kasonchan >> equations-monooperation_2.11 version0.1.1 in your project
reading data from excel file and plotting graph
reading data from excel file and plotting graph  I am doing a project using NetBeans in which i have to take input an excel file and then using the data in excel file, i have to plot graphs based on CELL ID selected. please help
Cramers rule for solving equations using java
Cramers rule for solving equations using java  My code: import... s=new Scanner(System.in); System.out.println("enter no of equations of matrix... double[N]; } System.out.println("enter the co-efficient of equations
Maven dependency for com.kasonchan - equations-monooperation_2.11 version 0.1.1 is released. Learn to use equations-monooperation_2.11 version 0.1.1 in Maven based Java projects
Maven dependency for  com.kasonchan  - Version 0.1.1 of equations... - equations-monooperation_2.11 project have released the latest version of this library on 02 Dec 2015, the released version of  com.kasonchan - equations
Maven dependency for com.kasonchan - equations-massbalance_2.11 version 0.1.1 is released. Learn to use equations-massbalance_2.11 version 0.1.1 in Maven based Java projects
Maven dependency for  com.kasonchan  - Version 0.1.1 of equations... - equations-massbalance_2.11 project have released the latest version of this library on 02 Dec 2015, the released version of  com.kasonchan - equations
gauss elimination of system of linear equations using java code
gauss elimination of system of linear equations using java code  Here...); System.out.println("enter no of equations "); N = s.nextInt...]; } System.out.println("enter the co-efficient of equations
Default constructor generate two random equations

Ads