Home Answers Viewqa Java-Beginners Plotting equations on a cartesian Plane

 
 


Umar Kagee
Plotting equations on a cartesian Plane
0 Answer(s)      9 months ago
Posted in : Java Beginners

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 Pages:
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
What is a Cartesian product?
What is a Cartesian product?   What is a Cartesian product?   Hi, Here is the answer, The Cartesian product, also referred to as a cross... and STORE tables have 5 rows. If we use a Cartesian join in these two tables
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
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
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
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
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
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
Draw a Mandelbrot
Draw a Mandelbrot       In this section, you will studied how to draw a Mandelbrot. A Mandelbrot is a collection of points in the plane whose boundary forms a fractal
Cross Join Tables in a Specific Database
tables as a Cartesian product of set theory in mathematics. Each row will get... rows, then the cartesian of two table will be six. See brief description below... as Cartesian product format of set theory in mathematics. All rows are shown
Mysql Cross Join
Mysql Cross Join       Cross Join is also called Cartesian Product Join. The Cross Join in SQL return you  a result table in which each row from the first table is combined
java programming - Java Beginners
java programming  asking for java code, solving three unknowns in three equations..I need the thx ahed
java programming - Java Beginners
java programming  asking for the java code for solving mathematical equation with two unknown .thnx ahead..  Hi Friend, Please clarify your question. Which mathematical equations you want to solve? Thanks
generating mock data class of times (start and end time and value)
generating mock data class of times (start and end time and value)   Using the timertask function want to generate a set of mock data of times using the random DATE class and values for plotting on a graph using java. How
java + grid - Java3D
java + grid  i need to give the output of the application in the form of a grid in XY-plane,the grid should have different colors for regions of different value range
Java Arrary - Java Beginners
Java Arrary  Use an array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array
Java Programming: Solution to Programming Exercise
should represent a fixed region in the xy-plane, defined by -5 <= ... is drawn on a canvas which represents the region of the (x,y)-plane given... that lies outside this region is not shown. The graph is drawn by plotting
surface chart - Java3D
surface chart  i have to make a surface chart of a piece of land with data given for each point in the xy plane....the chart should be such that the areas with different data range should show up in different colour. seriously
airline reservation - Java Beginners
airline reservation example  (Airline Reservation System) A small airline has just purchases a computer for its new automated reservations system. You have... seats on each flight of the airlines? only plane (capacity: 10 seats
C Programming
C Programming  hi,how can i write a program in C programming to place reservation in air plane from the menu let the user to inter his/her gender(W or M)and draw seats by using ascii codes and choose where he/she will sit
Need the Following MobileApplication Related Code
: Delete the Subscriber: Rate Plane Decrease when we called
jMATLAB
plotting capabilities. Above all, the extendable java architecture allows a power
importing excel file and drawing multiple graphs from one excel file
importing excel file and drawing multiple graphs from one excel file  thanks a lot sir for replying with code for importing excel file and then plotting grph:) it really helped me:):) If you can please help me with one more thing
Merge XYLine and XYArea Charts
appreciate any help. Please, bear in mind I am new to charts plotting in java
Java Programming: Chapter 9 Exercises
, from Section 3, to solve equations specified by the user. static... represent a fixed region in the xy-plane, defined by -5 <= x 
java compilation - UML
, we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Design the class circle that can store the radius and the center of the circle. Because the center is a point in the x-y plane and you
i want code for these programs
, and execute a program to solve a system of n linear equations using Successive Over
please help.. this my importtant project..!!!!!
please help.. this my importtant project..!!!!!  Consider the Algebra: Solving quadratic equations. The two roots of a quadratic equation ax2 + bx + c = 0 can be obtained using the formula: ð???ð???ð???ð??¡1= â??ð???+â??ð???2â
Java find the roots of quadratic equation
Java find the roots of quadratic equation In this tutorial, you will learn how to find the roots of quadratic equation. Quadratic Equations are always in the form ax2 + bx + c = 0. Every Quadratic equation has two roots
Inheritance - Java Beginners
Inheritance  This is only one problem. A point in the x-y plane... and circumference. Given the center we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Design a class Circle that can store
java compilation - Java3D
java compilation  A point in the x-y plane is represented by its x-coordinate and y-coordinate.Design the class point that can store and process a point in the x-y plane. you should then perform operations on a point, printig
Inheretance and polymorphism - Java Beginners
Inheretance and polymorphism  hope guys you will help ,thank you. merry christmas and happy new year to you! Exercise 1.) A point the x-y plane... in the x-y plane and you designed the class to capture the properties of a point
Quadratic Equation - Java Beginners
Quadratic Equation  Write a program that will determine the roots of quadratic equations ax^2 + bx +c. the program should repeatedly prompt the user for values of a, b, and c. For each set of values, the program should solve
java - Java Beginners
cartesian(int i){ return data[i]; } // return a string representation
java - Java Beginners
the corresponding unit vector public double cartesian(int i){ return data[i
Hibernate Query Language
with dynamic profiling, Inner/outer/full joins, Cartesian products. It also supports
Types of Graphs and Charts
rather than Cartesian coordinates. In a Polar Chart the dataset having
Web Development for iPhone
we are super specialist. Before plotting the sketch of preparing the site, our
SQL Join
Cross Join Cross Join is also called Cartesian Product Join. The Cross
Java program? - Java Beginners
velocity of the planet using the following equations: vescape = square root(2
Animation in Applets - Applet
Animation in Applets  Hello sir, I have a code for you .this code is for moving a plane in an applet,but unfortunatly this code is not working .can you kindly help me out to solve this problem. code: import
Basics of Global Positioning System
to the equatorial plane. All these satellites are controlled by the GPS Master
GPS Capability
in the 6 orbit planes (four satellites in each plane) continuously signaling signals
GPS in Cargo Tracking
in all most all means of commercial transport including ship, plane, train, van
PlotChart Control in Flex4
PlotChart control in Flex4: The PlotChart Control is a MX Component. There is no Spark component. The PlotChart Control represents the each data value by a single point. This point represents the Cartesian coordinate position along
Java Programming: Solution to Programming Exercise
3, to solve equations specified by the user. static double root(double
Multiplication of two polynomials using linked list in java
for the equations public void print(){ Node p = front; while(p != null){ System.out.print
java netbean - UML
only plane. Type of travel selection Denoted as Seat numbers assigned First
Inheretance and polymorphism - Java Beginners
Inheretance and polymorphism  FRIEND IS THIS ONE CODE??? hope guys you will help ,thank you. merry christmas and happy new year to you! 1.) A point the x-y plane is coordinate and y-coordinate.Design the class Point

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.