I am trying to make a polynomial graph plotter. It takes the degree for a polynomial and then starts taking coefficients one by one.

I want to set its scaling like i want its coordinates not set to the pixels but each coordinate should be 10 or more pixels away from the other coordinate. And one more problem is when I give higher degrees to the program, it does not give an appropriate graph. Kindly tell what is the issue with that program. I am using two different classes. One of them is :

 
 
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
import java.awt.Color;
 
 
public class gr03_draw extends JPanel {
 
	private int []coEffi; // array for coefficients
 
	public gr03_draw(int []userChoice) // takes an array filled with coefficients
	{
		coEffi=userChoice;  //assigns the array to another one
	}
 
	public void paintComponent(Graphics gx){
 
		super.paintComponent(gx);
		Graphics2D g=(Graphics2D)gx;
 
 
		int width= getWidth();
		int height= getHeight();
 
		g.setColor(Color.WHITE);  //setting background color
		g.fillRect(0, 0, width, height);
 
 
		g.setColor(Color.RED);
 
		g.drawLine(0, height/2, width, height/2); // x-axis line
		g.drawLine(width/2, 0, width/2, height); //y-axis line
		int degree=coEffi.length-1;
 
		for(int x=-width; x<=width; x++) //finds the ordinates from given values of x
		   {
		     int y=0;
		     int y2=0;
		     for(int i=0; i<=degree; i++) //finds the y1 for the line
		     {
		       y+=(coEffi[i]*Math.pow(x,i));
		     }
		     for(int i2=0; i2<=degree; i2++) //finds the y2 for the line
		     {
		       y2+=(coEffi[i2]*Math.pow(x+1,i2));
		     }
                  /*Following three lines are used to hold origin at the center I am not using "translate" here, as I was unable to set the direction of y-axis from*/
		  int pntX=(width/2)+x;
		  int pntY=height-((height/2)+y);
		  int pntY2=height-((height/2)+y2);
//it draws the lines
		  g.drawLine(pntX, pntY, pntX+1, pntY2);
 
		  }//end of loop
	}
 
 
}

And another class is:

 
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class gr03_draw2 {
 
 
	public static void main(String[] args) {
 
		String inputDeg=JOptionPane.showInputDialog("Tell the Degree of Polynomial");
 
		int degree=Integer.parseInt(inputDeg);
 
		JOptionPane.showMessageDialog(null, "Start entering co-efficients one by one");
 
		int []coef=new int[degree];
 
		for(int i=0; i<coef.length; i++)
		{
			String inputCo=JOptionPane.showInputDialog("Tell the Degree of Polynomial");
			coef[i]=Integer.parseInt(inputCo);
		}
 
		gr03_draw panel = new gr03_draw(coef);
 
		JFrame appli= new JFrame();
                 // I tried the following line to set distance between the coordinates
		//setLayout(new GridLayout(1,1,20,20)); 
		appli.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
		appli.add(panel);
 
		appli.setSize(400, 500);
 
		appli.setVisible(true);
 
	}
 
}