import java.awt.*;import java.awt.event.*;import java.applet.*;import java.net.URL;import java.util.*;import graph.*;/*****************************************************************************    Applet linear1a**                                              Version 1.0   January 1996******************************************************************************    Copyright (C) 1996 Leigh Brookshaw****    This program is free software; you can redistribute it and/or modify**    it under the terms of the GNU General Public License as published by**    the Free Software Foundation; either version 2 of the License, or**    (at your option) any later version.****    This program is distributed in the hope that it will be useful,**    but WITHOUT ANY WARRANTY; without even the implied warranty of**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the**    GNU General Public License for more details.****    You should have received a copy of the GNU General Public License**    along with this program; if not, write to the Free Software**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.******************************************************************************    This is a simple applet that demonstrates how to use the basic features**    of the Plotting Class library. The data is calculated locally by**    the applet***************************************************************************/public class linear_ckt extends Applet implements AdjustmentListener{	LoadData dynamic;      	Graph2D graph1;      	Image osi=null;	Graphics osg=null;int iwidth = 0;int iheight=0;	DataSet data1;      	DataSet data2;	DataSet data3;	DataSet data4;      	Axis    xaxis1;      	Axis    yaxis1;      	double data[];      	int np = 10;      	URL markersURL;      	Markers markers;      	Panel      panel;     	 Label title;	Button dolbear, bessey;	Scrollbar slope, intercept;	TextField equation, slopetext,intercepttext;	int i,j; double m1,m2,m3,m4; 	double aa=52; 	double bb=55; int lx =100; int ly = 100; double az=200; double bz=85;	int mx=100; int my=100;	      public void init() {                double data[] = new double[2*np];	        setLayout( new BorderLayout() );						dolbear= new Button("Dolbear");				bessey=new Button("Bessey");		equation=new TextField("Line Equation: ", 20);		add("South", equation);		equation.reshape(200, 350,300,30);		add(bessey); add(dolbear);		dolbear.reshape(130,20,50,18);		bessey.reshape(200,20,50,18);		intercept = new Scrollbar(Scrollbar.HORIZONTAL, 200,1,0,500);		add("South", intercept);intercept.reshape(500,380,150,10);		intercept.addAdjustmentListener(this);		TextField intercepttext=new TextField(20);		intercepttext.reshape(450,360,50,20);		TextField slopetext=new TextField(20);		slopetext.setText(String.valueOf(m3)); slopetext.reshape(100,360,30,20);		slope = new Scrollbar(Scrollbar.HORIZONTAL, 25,1,1,100);		add("South",slope); slope.reshape(50,380,150,10);		slope.addAdjustmentListener(this);		Label interceptlabel=new Label("Intercept");		add("South", interceptlabel); interceptlabel.reshape(450,380,50,20);		Label slopelabel=new Label("Slope"); 		add("South",slopelabel);/*	**      Get the passed parameters*/        String st = getParameter("TITLE");        String mfile    = getParameter("MARKERS");	String points =getParameter("POINTS");/***      Create the Graph instance and modify the default behaviour*/        graph1 = new Graph2D();	dynamic = new LoadData();        graph1.drawzero = false;        graph1.drawgrid = true;        graph1.borderRight = 0;        graph1.setDataBackground(new Color(150,230,200));	        /***      Build the title*/        title = new Label(st, Label.CENTER);        title.setFont(new Font("TimesRoman",Font.PLAIN,20));/***      Load a file containing Marker definitions*/        try {           markersURL = new URL(getDocumentBase(),mfile);           markers = new Markers(markersURL);	 } 	   catch(Exception e) 	{           System.out.println("Failed to create Marker URL!");        }                 graph1.setMarkers(markers);        add("Center", graph1);/***      Calculate the first data Set.*/        for(i=j=0; i<np; i++,j+=2) {            data[j] = 50+18*i;            data[j+1] = 50+(data[j]-40)/4;        }        data1 = graph1.loadDataSet(data,np);        data1.linecolor   =  Color.red;        data1.linestyle = 0;        data1.marker    = 0;        data1.markerscale = 1.0;        data1.markercolor = new Color(0,0,255);        data1.legend(100,50,"Dolbear   T=0.25N + 40");        data1.legendColor(Color.black);/***      Calculate the Second data Set.*/        for(i=j=0; i<np; i++,j+=2) {            data[j] = 50+18*i;            data[j+1] = 0.21*data[j]+40.4;        }        data2 = graph1.loadDataSet(data, np);        data2.linecolor   =  Color.magenta;        data2.linestyle = 0;	data2.marker      = 0;        data2.markercolor = new Color(100,100,255);        data2.legend(100,75,"Bessey   T=0.21N + 40.4");        data2.legendColor(Color.black);/***      Start a new thread and load the data*/        try {        data3 = dynamic.loadDataSet(new URL(getDocumentBase(),points), graph1);        } catch (Exception e) {          System.out.println("Failed to load data file!");        }/***      Specify the data line color*/       data3.linecolor   =  new Color(0,255,0);	data3.linestyle=0;        data3.marker      = 4;        data3.markercolor = new Color(0,0,0);        data3.legend(100,100,"Bessey   data");        data3.legendColor(Color.black); /***	data set 4*/	 m1=25;m2=40; m3=m1/100;	 for(i=j=0; i<np; i++,j+=2) {            data[j] = 50+20*i;            data[j+1] = (m3*data[j] + m2);        }        data4 = graph1.loadDataSet(data,np);                      data4.linecolor   =  Color.blue;        data4.linestyle = 1;        data4.marker    = 0;        data4.markerscale = 1.0;        data4.markercolor = new Color(0,0,255);                /*	**      Attach data sets to the Xaxes*/        xaxis1 = graph1.createAxis(Axis.BOTTOM);        xaxis1.attachDataSet(data1);	xaxis1.attachDataSet(data2);	xaxis1.attachDataSet(data3);	xaxis1.attachDataSet(data4);        xaxis1.setTitleText("Chirps per Minute");        xaxis1.setTitleFont(new Font("TimesRoman",Font.PLAIN,20));        xaxis1.setLabelFont(new Font("Helvetica",Font.PLAIN,15));
 	xaxis1.setTitleColor( new Color(0,0,255) );        /***      Attach the first data set to the Left Axis*/        yaxis1 = graph1.createAxis(Axis.LEFT);        yaxis1.attachDataSet(data1);        yaxis1.attachDataSet(data2);	yaxis1.attachDataSet(data3);	yaxis1.attachDataSet(data4);        yaxis1.setTitleText("Temperature (Farenheit)");        yaxis1.setTitleFont(new Font("TimesRoman",Font.PLAIN,20));        yaxis1.setLabelFont(new Font("Helvetica",Font.PLAIN,15));        yaxis1.setTitleColor( new Color(0,0,255) );        yaxis1.setTitleRotation(90);			}	public boolean action(Event eve, Object arg)	{if (eve.target instanceof Button) 		showLine((String)arg);	backburner();	return true;	}	void showLine(String bname)		{if (bname.equals("Dolbear"))			{ if (data1.linestyle==0)					{data1.linestyle=1;}			else				{data1.linestyle=0;}			}		else 		{if (bname.equals("Bessey")) 			{if (data2.linestyle==0)					{data2.linestyle=1;}			else				{data2.linestyle=0;}			}		}		}		void backburner(){
Graphics g;
 g = graph1.getGraphics();                   if( osi == null || iwidth != graph1.size().width                                   || iheight != graph1.size().height  ) {                       iwidth = graph1.size().width;                       iheight = graph1.size().height;                       osi = graph1.createImage(iwidth,iheight);                       osg = osi.getGraphics();                   }                   osg.setColor(this.getBackground());                   osg.fillRect(0,0,iwidth,iheight);                   osg.setColor(g.getColor());                   osg.clipRect(0,0,iwidth,iheight);                   graph1.update(osg);                   g.drawImage(osi,0,0,graph1);        								}public void adjustmentValueChanged(AdjustmentEvent ade)	{ lx = intercept.getValue();		intercept.setValue(lx);		ly = slope.getValue();		slope.setValue(ly);		m1= ly; m4=lx; m3=m1/100;m2=m4/5;		double other[]= new double[2*np];	 for(i=j=0; i<np; i++,j+=2) {            other[j] = 50+20*i;            other[j+1] = (m3*other[j] + m2);        }        		data4.delete(0,np);		try{    data4.append(other,np);}		                        catch (Exception e) {                        System.out.println("Error appending Data!");                   }               xaxis1.setManualRange(true);		data4.xaxis.minimum=50.0; data4.xaxis.maximum=225.0;		yaxis1.setManualRange(true);		        data4.yaxis.minimum=50.0; data4.yaxis.maximum=85.0;  		   equation.setText(" Line Equation: T= "+m3+"N + "+m2);                 equation.setFont(new Font("TimesRoman",Font.PLAIN,20));  			backburner();							}public void update(Graphics screen){	paint(screen);	}			 }        		

