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 mandm1w 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 data4;
      	Axis    xaxis1;
      	Axis    yaxis1;
      	double data[];
      	int np = 200;
 
      	Panel      panel;
     	 Label title;
	
	Scrollbar V, K;
	TextField  Vtext,Ktext, equationtext;
	int i,j; double m1,m2,V1,K1; 
	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() );		
		Vtext =new TextField(" ",50);
		add("South", Vtext);Vtext.reshape(130,350,75,25);
		Ktext = new TextField(" ",50);
		add("South", Ktext);Ktext.reshape(620,350,75,25);	
		equationtext = new TextField("R = V.S/(K+S)");
		add("North",equationtext); equationtext.reshape(10, 10, 100, 25);
		K = new Scrollbar(Scrollbar.HORIZONTAL, 100,1,0,200);
		add("South", K);K.reshape(500,380,200,10);
		K.addAdjustmentListener(this);
		V = new Scrollbar(Scrollbar.HORIZONTAL, 1000,50,0,3000);
		add("South",V); V.reshape(50,380,200,10);
		V.addAdjustmentListener(this);
		Label Klabel=new Label("K");

		add("South", Klabel); Klabel.reshape(450,380,50,20);

		Label Vlabel=new Label("V"); 

		add("South",Vlabel); 


/*
**      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(235,149,235));
	

        add("Center", graph1);

/*

**      Calculate the first data Set.

*/

        data[0]=0; data[1]=0; data[2]=5000; data[3]=3500;

        data1 = graph1.loadDataSet(data,2);

        data1.linecolor   =  Color.red;

        data1.linestyle = 0;

 	data[0]=0; data[1]=1000.00; data[2]=5000; data[3]=1000.00;
	data2 = graph1.loadDataSet(data,2);

        data2.linecolor   =  Color.white;

        data2.linestyle = 1;
/*
**	data set 4
*/
	 V1=1000.00;K1=100.0; 
	 for(i=j=0; i<np; i++,j+=2) {
            data[j] = (i*1.0)*25;
            data[j+1] = (V1*data[j])/(K1+data[j]);
        }
        data4 = graph1.loadDataSet(data,np);
          
        data4.linecolor   =  Color.black;
        data4.linestyle = 1;
      
        Vtext.setText(" "+(int)V1+" nm/s");
	Ktext.setText(" "+(int)K1+"µM");
        
        
/*	
**      Attach data sets to the Xaxes
*/
        xaxis1 = graph1.createAxis(Axis.BOTTOM);
  	xaxis1.attachDataSet(data1); 
	xaxis1.attachDataSet(data2); 
	xaxis1.attachDataSet(data4);
        xaxis1.setTitleText("S");
        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(data4);
        yaxis1.setTitleText("R");
        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 void adjustmentValueChanged(AdjustmentEvent ade)
	{ lx = K.getValue();
		K.setValue(lx);
		ly = V.getValue();
		V.setValue(ly);
		m1= ly; m2=lx ; V1=m1*1.0; K1=m2*1.0;
 		Vtext.setText(" "+( int)V1+" nm/s");
		Ktext.setText(" "+( int)K1+"µM");
		equationtext.setText("R = "+(int)V1+"S/("+(int)K1+"+S)");
Graphics g;
		double other[]= new double[2*np];
	 for(i=j=0; i<np; i++,j+=2) {
            other[j] = (i*1.0)*25;
            other[j+1] = (V1*other[j])/(K1+other[j]);
        }
        
		data4.delete(0,np);
		try{    data4.append(other,np);}
		     
                   catch (Exception e) {
                        System.out.println("Error appending Data!");
                   }
        		other[0]=0.0; other[1]=V1; other[2]=5000.0; other[3]=V1;

		data2.delete(0,2);
		try{    data2.append(other,2);}
		     
                   catch (Exception e) {
                        System.out.println("Error appending Data!");
                   }
       xaxis1.setManualRange(true);
		data4.xaxis.minimum=0.00; data4.xaxis.maximum=5000.0;
		yaxis1.setManualRange(true);
		        data4.yaxis.minimum=0.0; data4.yaxis.maximum=3500.0;  
		   
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);
	osg.setColor(Color.black);
	osg.drawString("x10^3", 650, 300);
                   g.drawImage(osi,0,0,graph1);
			
	}

public void update(Graphics screen){
	paint(screen);
	}
		
	
 

}

        
		




