Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Umar Kagee
Plotting equations on a cartesian Plane
0 Answer(s)      2 years and 5 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:)


Advertisement
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
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
Advertisements
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
. A Mandelbrot is a collection of points in the plane whose boundary forms a fractal..., q))   writableRaster.setDataElements(j, k, object...(double p, double q) {   double x = 0.4
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
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 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 + 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
Moving Applet Problem
; Thread t1=new Thread(this); int maxx=0,maxy=0; Image plane...); setBackground(Color.BLACK); plane=getImage(getDocumentBase... public void paint(Graphics g) { g.drawImage(plane, maxx, maxy
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
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
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
Need the Following MobileApplication Related Code
: Delete the Subscriber: Rate Plane Decrease when we called
Merge XYLine and XYArea Charts
appreciate any help. Please, bear in mind I am new to charts plotting in java
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
jMATLAB
plotting capabilities. Above all, the extendable java architecture allows a power
write a java program that implements the following classes:
write a java program that implements the following classes:  write a java program that implements the following classes: A) a) Point in the Cartesian coordinate system. b) Circle with a given center and radius c) Cylinder
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
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
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
i want code for these programs
, and execute a program to solve a system of n linear equations using Successive Over
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
 

 

 

DMCA.com