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 PlanePlotting 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
plotting a graph - Java Beginnersplotting 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 rectangleplotting 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 planereservation 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 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-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
reading data from excel file and plotting graphreading 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 javaCramers 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