import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;

public class Plot2D extends JApplet
{
    public Plot p1;     
   
    public void init() 
    {
        //Initialize drawing colors
        setBackground(Color.white);
        setForeground(Color.black);
       
    }

    public void paint(Graphics g) throws IOException 
    {
        try{
           p1=new Plot();
           } catch(IOException ioe) 
            {System.err.println("IOException in opening Plot");}
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,       RenderingHints.VALUE_ANTIALIAS_ON);
        Dimension d = getSize();
        int gridWidth = d.width;
        int gridHeight = d.height;
        inputXmin.setText(Double.toString(p1.xmin));
        inputXmax.setText(Double.toString(p1.xmax));
        inputYmin.setText(Double.toString(p1.ymin));
        inputYmax.setText(Double.toString(p1.ymax));
        PlotShapes ps=new PlotShapes(g2,p1.xabsmin,p1.yabsmin,
        p1.absheight,p1.abswidth,p1.xmin,p1.xmax,p1.ymin,p1.ymax);
        g2.draw(newdrawRect2D.Double(p1.xabsmin,
        p1.yabsmin,p1.abswidth,p1.absheight));
        ps.drawXTic(p1.xntic,(p1.ymax-p1.ymin)/80.0,0);
        ps.drawYTic(p1.yntic,(p1.xmax-p1.xmin)/80.0,0);
        ps.drawXNumbers(p1.xntic);
        ps.drawYNumbers(p1.xntic);
        ps.drawLabel(p1.label);
        ps.drawXLabel(p1.xlabel);
        ps.drawYLabel(p1.ylabel);
        if(p1.xgridon!=0)
          ps.drawXGrid(p1.xntic);
        if(p1.ygridon!=0)
          ps.drawYGrid(p1.yntic);
        int i,j;
        for(i=0;i<p1.nline;i++)
          {
          //  Select plot colors
          g.setPaint(new Color(p1.red[i],p1.green[i],p1.blue[i]));
          ps.drawPlotLines(i,p1.plottype,p1.x,p1.y,p1.n,p1.ch);
    }
}
