/******************************** * Class to plot the function * ********************************/ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Plotter extends Canvas { double x_min, x_max, y_min, y_max; double [] coefs = null; int [] x_points = null; int [] y_points = null; public Plotter() { super(); Color myblue = new Color(10,10,100); setBackground(myblue); x_min = -100.0; x_max = 100.0; y_min = -100.0; y_max = 100.0; x_points = new int[100]; y_points = new int[100]; } public Dimension getPreferredSize() { return new Dimension(400,200); } public void paint (Graphics g) { g.setColor(Color.white); Dimension size = getSize(); int xo = (int) (size.width * (-x_min) / (x_max-x_min)); int yo = (int) (size.height * (-y_max) / (y_min-y_max)); g.drawLine(0, yo, size.width, yo); g.drawLine(xo, 0, xo, size.height); g.drawString("x", size.width-20, yo+20); g.drawString("y", xo+10, 20); /******************************* for (int j=0; j<100; j++) { g.drawString("|", xo+(10*j), yo+5); } for (int j=0; j<100; j++) { g.drawString("-", xo, yo-(10*j)); } ******************************/ if (coefs != null) { g.setColor(Color.yellow); calcpoints(); g.drawPolyline(x_points, y_points, x_points.length); } } public void calcpoints() { Dimension size = getSize(); for (int i=0; i