/*
To do Rhodes' modeling - 7/98 EFG
Interface tweaking - 10/98 EFG
Modified - 08/2000 DR
*/

import java.awt.*;
import java.applet.Applet;

public class model extends Applet
{
TextField  textA1, textA2, textA5, textA6;
TextField  textG1, textB1, textB2;
TextField  textP1, textP2, textC1, textC2; 
TextField  textD1, textD2, textD5;
TextField  textE1, textE2, textE5;
TextField  textF1, textF2;
TextField  textKm1, textKm2, textKm3, textKm4, textKm5, textKm6, textKm7, textKm8, textKm9, textKm10, textKm11;
TextField  textVm1, textVm2, textVm3, textVm4, textVm5, textVm6, textVm7, textVm8, textVm9, textVm10, textVm11;
TextField  textTS;
TextField  textCS;
TextField  textBS;
TextField  textES;
TextField  textMy1;
TextField  textMy2;
Label      endXAxis1, endXAxis2;
Label      endYAxis1, endYAxis2;
Button     bDoGraph;
Graph		isotopeGraph, poolGraph;
static final int GraphSize = 200;

public void init() {

// Arrange the user interface using a gridbag.
GridBagConstraints gbc;
GridBagLayout  gb;
gb = new GridBagLayout();
setLayout(gb); // set the layout for the whole applet

// add the data entry fields
Label labelP1 = new Label("P1:");
textP1 = new TextField("54", 6);
Label labelP2 = new Label("P2:");
textP2 = new TextField("170", 6);
Label labelG1 = new Label("G1:");
textG1 = new TextField("0", 6);
Label labelA1 = new Label("A1:");
textA1 = new TextField("0", 6);
Label labelA2 = new Label("A2:");
textA2 = new TextField("2.0", 6);
Label labelA5 = new Label("A5:");
textA5 = new TextField("0", 6);
Label labelA6 = new Label("A6:");
textA6 = new TextField("70", 6);
Label labelB1 = new Label("B1:");
textB1 = new TextField("0", 6);
Label labelB2 = new Label("B2:");
textB2 = new TextField("0.2", 6);
Label labelC1 = new Label("C1:");
textC1 = new TextField("0", 6);
Label labelC2 = new Label("C2:");
textC2 = new TextField("30", 6);
Label labelD1 = new Label("D1:");
textD1 = new TextField("0", 6);
Label labelD2 = new Label("D2:");
textD2 = new TextField("70", 6);
Label labelD5 = new Label("D5:");
textD5 = new TextField("0.166", 6);
Label labelE1 = new Label("E1:");
textE1 = new TextField("0", 6);
Label labelE2 = new Label("E2:");
textE2 = new TextField("1800", 6);
Label labelE5 = new Label("E5:");
textE5 = new TextField("0.056", 6);
Label labelF1 = new Label("F1:");
textF1 = new TextField("0", 6);
Label labelF2 = new Label("F2:");
textF2 = new TextField("0.2", 6);
Label labelKm1 = new Label("Km1:");
textKm1 = new TextField("50", 6);
Label labelKm2 = new Label("Km2:");
textKm2 = new TextField("40", 6);
Label labelKm3 = new Label("Km3:");
textKm3 = new TextField("80", 6);
Label labelKm4 = new Label("Km4:");
textKm4 = new TextField("200", 6);
Label labelKm5 = new Label("Km5:");
textKm5 = new TextField("2000", 6);
Label labelKm6 = new Label("Km6:");
textKm6 = new TextField("40", 6);
Label labelKm7 = new Label("Km7:");
textKm7 = new TextField("400", 6);
Label labelKm8 = new Label("Km8:");
textKm8 = new TextField("20", 6);
Label labelKm9 = new Label("Km9:");
textKm9 = new TextField("40", 6);
Label labelKm10 = new Label("Km10:");
textKm10 = new TextField("2000", 6);
Label labelKm11 = new Label("Km11:");
textKm11 = new TextField("350", 6);
Label labelVm1 = new Label("Vm1:");
textVm1 = new TextField("30", 6);
Label labelVm2 = new Label("Vm2:");
textVm2 = new TextField("3.1", 6);
Label labelVm3 = new Label("Vm3:");
textVm3 = new TextField("2.5", 6);
Label labelVm4 = new Label("Vm4:");
textVm4 = new TextField("0.15", 6);
Label labelVm5 = new Label("Vm5:");
textVm5 = new TextField("0.6", 6);
Label labelVm6 = new Label("Vm6:");
textVm6 = new TextField("0.55", 6);
Label labelVm7 = new Label("Vm7:");
textVm7 = new TextField("0.45", 6);
Label labelVm8 = new Label("Vm8:");
textVm8 = new TextField("0.55", 6);
Label labelVm9 = new Label("Vm9:");
textVm9 = new TextField("2.0", 6);
Label labelVm10 = new Label("Vm10:");
textVm10 = new TextField("0.7", 6);
Label labelVm11 = new Label("Vm11:");
textVm11 = new TextField("0.0725", 6);
Label labelTS = new Label("TS:");
textTS = new TextField("650.0", 6);
Label labelCS = new Label("CS:");
textCS = new TextField("0.02", 6);
Label labelBS = new Label("BS:");
textBS = new TextField("0.02", 6);
Label labelES = new Label("ES:");
textES = new TextField("10", 6);
Label labelMR = new Label("MR:");
textMy1 = new TextField("10000.0", 6);
Label labelMP = new Label("MP:");
textMy2 = new TextField("250.0", 6);
Label gLabel1 = new Label("Radioactivity");
Label xLabel1 = new Label("Time (min)");
Label yLabel1 = new Label("nCi.g(-1) Fw");
Label startXAxis1 = new Label ("0");
Label startYAxis1 = new Label ("0");
endXAxis1 = new Label (textTS.getText());
endYAxis1 = new Label (textMy1.getText());
isotopeGraph = new Graph(GraphSize, GraphSize);
isotopeGraph.graphImage = blankGraph(GraphSize, GraphSize);
bDoGraph = new Button ("Start");
Label gLabel2 = new Label("Pool size");
Label xLabel2 = new Label("Time (min)");
Label yLabel2 = new Label("nmol.g(-1) Fw");
Label startXAxis2 = new Label ("0");
Label startYAxis2 = new Label ("0");
endXAxis2 = new Label (textTS.getText());
endYAxis2 = new Label (textMy2.getText());
poolGraph = new Graph(GraphSize, GraphSize);
poolGraph.graphImage = blankGraph(GraphSize, GraphSize);

gbc = new GridBagConstraints();
gbc.gridx = gbc.gridy = 0;
gb.setConstraints(labelP1,  gbc);
add(labelP1);
gbc.gridy = 1;
gb.setConstraints(labelP2,  gbc);
add(labelP2);
gbc.gridy = 2;
gb.setConstraints(labelA1,  gbc);
add(labelA1);
gbc.gridy = 3;
gb.setConstraints(labelA2,  gbc);
add(labelA2);
gbc.gridy = 4;
gb.setConstraints(labelA5,  gbc);
add(labelA5);
gbc.gridy = 5;
gb.setConstraints(labelA6,  gbc);
add(labelA6);
gbc.gridy = 6;
gb.setConstraints(labelB1,  gbc);
add(labelB1);
gbc.gridy = 7;
gb.setConstraints(labelB2,  gbc);
add(labelB2);

gbc.gridy = 10;
gbc.anchor = GridBagConstraints.NORTHEAST;
gb.setConstraints(endYAxis1,  gbc);
add(endYAxis1);
gbc.gridy = 12;
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridheight = 3;
gb.setConstraints(yLabel1,  gbc);
add(yLabel1);
gbc.gridy = 14;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.SOUTHEAST;
gb.setConstraints(startYAxis1,  gbc);
add(startYAxis1);

gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gb.setConstraints(textP1,  gbc);
add(textP1);
gbc.gridy = 1;
gb.setConstraints(textP2,  gbc);
add(textP2);
gbc.gridy = 2;
gb.setConstraints(textA1,  gbc);
add(textA1);
gbc.gridy = 3;
gb.setConstraints(textA2,  gbc);
add(textA2);
gbc.gridy = 4;
gb.setConstraints(textA5,  gbc);
add(textA5);
gbc.gridy = 5;
gb.setConstraints(textA6,  gbc);
add(textA6);
gbc.gridy = 6;
gb.setConstraints(textB1,  gbc);
add(textB1);
gbc.gridy = 7;
gb.setConstraints(textB2,  gbc);
add(textB2);

gbc.gridy = 9;
gbc.gridwidth = 5;
gb.setConstraints(gLabel1,  gbc);
add(gLabel1);
gbc.gridy = 10;
gbc.gridheight = 5;
gb.setConstraints(isotopeGraph,  gbc);
add(isotopeGraph);
gbc.gridy = 15;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
gb.setConstraints(startXAxis1,  gbc);
add(startXAxis1);

gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 0;
gb.setConstraints(labelC1,  gbc);
add(labelC1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelC2,  gbc);
add(labelC2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD1,  gbc);
add(labelD1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD2,  gbc);
add(labelD2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD5,  gbc);
add(labelD5);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelE1,  gbc);
add(labelE1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelE2,  gbc);
add(labelE2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelE5,  gbc);
add(labelE5);

gbc.gridy = 15;
gbc.gridwidth = 3;
gb.setConstraints(xLabel1,  gbc);
add(xLabel1);

gbc = new GridBagConstraints();
gbc.gridx = 3;
gbc.gridy = 0;
gb.setConstraints(textC1,  gbc);
add(textC1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textC2,  gbc);
add(textC2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD1,  gbc);
add(textD1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD2,  gbc);
add(textD2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD5,  gbc);
add(textD5);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textE1,  gbc);
add(textE1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textE2,  gbc);
add(textE2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textE5,  gbc);
add(textE5);

gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = 0;
gb.setConstraints(labelF1,  gbc);
add(labelF1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelF2,  gbc);
add(labelF2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelG1,  gbc);
add(labelG1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm1,  gbc);
add(labelKm1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm2,  gbc);
add(labelKm2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm3,  gbc);
add(labelKm3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm4,  gbc);
add(labelKm4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm5,  gbc);
add(labelKm5);

gbc = new GridBagConstraints();
gbc.gridx = 5;
gbc.gridy = 0;
gb.setConstraints(textF1,  gbc);
add(textF1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textF2,  gbc);
add(textF2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textG1,  gbc);
add(textG1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm1,  gbc);
add(textKm1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm2,  gbc);
add(textKm2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm3,  gbc);
add(textKm3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm4,  gbc);
add(textKm4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm5,  gbc);
add(textKm5);

gbc.gridy = 15;
gbc.anchor = GridBagConstraints.NORTHEAST;
gb.setConstraints(endXAxis1,  gbc);
add(endXAxis1);

gbc = new GridBagConstraints();
gbc.gridx = 6;
gbc.gridy = 0;
gb.setConstraints(labelKm6,  gbc);
add(labelKm6);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm7,  gbc);
add(labelKm7);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm8,  gbc);
add(labelKm8);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm9,  gbc);
add(labelKm9);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm10,  gbc);
add(labelKm10);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelKm11,  gbc);
add(labelKm11);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm1,  gbc);
add(labelVm1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm2,  gbc);
add(labelVm2);

gbc = new GridBagConstraints();
gbc.gridx = 7;
gbc.gridy = 0;
gb.setConstraints(textKm6,  gbc);
add(textKm6);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm7,  gbc);
add(textKm7);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm8,  gbc);
add(textKm8);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm9,  gbc);
add(textKm9);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm10,  gbc);
add(textKm10);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textKm11,  gbc);
add(textKm11);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm1,  gbc);
add(textVm1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm2,  gbc);
add(textVm2);

gbc = new GridBagConstraints();
gbc.gridx = 8;
gbc.gridy = 0;
gb.setConstraints(labelVm3,  gbc);
add(labelVm3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm4,  gbc);
add(labelVm4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm5,  gbc);
add(labelVm5);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm6,  gbc);
add(labelVm6);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm7,  gbc);
add(labelVm7);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm8,  gbc);
add(labelVm8);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm9,  gbc);
add(labelVm9);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelVm10,  gbc);
add(labelVm10);

gbc.gridy = 10;
gbc.anchor = GridBagConstraints.NORTHEAST;
gb.setConstraints(endYAxis2,  gbc);
add(endYAxis2);
gbc.gridy = 12;
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridheight = 3;
gb.setConstraints(yLabel2,  gbc);
add(yLabel2);
gbc.gridheight = 1;
gbc.gridy = 14;
gbc.anchor = GridBagConstraints.SOUTHEAST;
gb.setConstraints(startYAxis2,  gbc);
add(startYAxis2);

gbc = new GridBagConstraints();
gbc.gridx = 9;
gbc.gridy = 0;
gb.setConstraints(textVm3,  gbc);
add(textVm3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm4,  gbc);
add(textVm4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm5,  gbc);
add(textVm5);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm6,  gbc);
add(textVm6);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm7,  gbc);
add(textVm7);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm8,  gbc);
add(textVm8);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm9,  gbc);
add(textVm9);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textVm10,  gbc);
add(textVm10);

gbc.gridy = 9;
gbc.gridwidth = 5;
gb.setConstraints(gLabel2,  gbc);
add(gLabel2);
gbc.gridy = 10;
gbc.gridheight = 5;
gb.setConstraints(poolGraph,  gbc);
add(poolGraph);
gbc.gridy = 15;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
gb.setConstraints(startXAxis2,  gbc);
add(startXAxis2);

gbc = new GridBagConstraints();
gbc.gridx = 10;
gbc.gridy = 15;
gbc.gridwidth = 3;
gb.setConstraints(xLabel2,  gbc);
add(xLabel2);

gbc.gridx = 6;
gbc.gridy = 13;
gbc.gridwidth = 1;
gb.setConstraints(bDoGraph,  gbc);
add(bDoGraph);

gbc = new GridBagConstraints();
gbc.gridx = 10;
gbc.gridy = 0;
gb.setConstraints(labelVm11,  gbc);
add(labelVm11);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelBS,  gbc);
add(labelBS);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelCS,  gbc);
add(labelCS);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelES,  gbc);
add(labelES);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelTS,  gbc);
add(labelTS);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelMR,  gbc);
add(labelMR);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelMP,  gbc);
add(labelMP);

gbc = new GridBagConstraints();
gbc.gridx = 11;
gbc.gridy = 0;
gb.setConstraints(textVm11,  gbc);
add(textVm11);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textBS,  gbc);
add(textBS);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textCS,  gbc);
add(textCS);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textES,  gbc);
add(textES);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textTS,  gbc);
add(textTS);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textMy1,  gbc);
add(textMy1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textMy2,  gbc);
add(textMy2);

gbc = new GridBagConstraints();
gbc.gridx = 13;
gbc.gridy = 15;
gbc.anchor = GridBagConstraints.NORTHEAST;
gb.setConstraints(endXAxis2,  gbc);
add(endXAxis2);

}

/*
public void update (Graphics g) { paint(g); }

public void paint (Graphics g) {
g.drawImage (graphImage, 0, 0, this);
}

public void run () {
repaint();
}*/

public boolean action(Event e, Object arg) {
if (e.target == bDoGraph) {
doGraph();
}
else
System.out.println("Unrecognized event");

return super.action(e, arg);
}

public void doGraph () {
bDoGraph.disable();

float P1 = floatFromTextField(textP1);
float P2 = floatFromTextField(textP2);
float G1 = floatFromTextField(textG1);
float A1 = floatFromTextField(textA1);
float A2 = floatFromTextField(textA2);
float A5 = floatFromTextField(textA5);
float A6 = floatFromTextField(textA6);
float B1 = floatFromTextField(textB1);
float B2 = floatFromTextField(textB2);
float C1 = floatFromTextField(textC1);
float C2 = floatFromTextField(textC2);
float D1 = floatFromTextField(textD1);
float D2 = floatFromTextField(textD2);
float D5 = floatFromTextField(textD5);
float E1 = floatFromTextField(textE1);
float E2 = floatFromTextField(textE2);
float E5 = floatFromTextField(textE5);
float F1 = floatFromTextField(textF1);
float F2 = floatFromTextField(textF2);
float Km1 = floatFromTextField(textKm1);
float Km2 = floatFromTextField(textKm2);
float Km3 = floatFromTextField(textKm3);
float Km4 = floatFromTextField(textKm4);
float Km5 = floatFromTextField(textKm5);
float Km6 = floatFromTextField(textKm6);
float Km7 = floatFromTextField(textKm7);
float Km8 = floatFromTextField(textKm8);
float Km9 = floatFromTextField(textKm9);
float Km10 = floatFromTextField(textKm10);
float Km11 = floatFromTextField(textKm11);
float Vm1 = floatFromTextField(textVm1);
float Vm2 = floatFromTextField(textVm2);
float Vm3 = floatFromTextField(textVm3);
float Vm4 = floatFromTextField(textVm4);
float Vm5 = floatFromTextField(textVm5);
float Vm6 = floatFromTextField(textVm6);
float Vm7 = floatFromTextField(textVm7);
float Vm8 = floatFromTextField(textVm8);
float Vm9 = floatFromTextField(textVm9);
float Vm10 = floatFromTextField(textVm10);
float Vm11 = floatFromTextField(textVm11);
float TS = floatFromTextField(textTS);
float CS = floatFromTextField(textCS);
float BS = floatFromTextField(textBS);
float ES = floatFromTextField(textES);
float Y1 = floatFromTextField(textMy1);
float Y2 = floatFromTextField(textMy2);

endXAxis1.setText(textTS.getText());
endXAxis2.setText(textTS.getText());
endYAxis1.setText(textMy1.getText());
endYAxis2.setText(textMy2.getText());

isotopeGraph.graphImage = blankGraph(GraphSize, GraphSize);
poolGraph.graphImage = blankGraph(GraphSize, GraphSize);

float A8;
float A3;
float A4;
float A7;
float B3;
float C3;
float D3;
float D4;
float E3;
float E4;
float F3;
float t;
float Z = TS / 2000;
for (t=0; t <= TS; t = t + Z) {
A8 = (Vm1*P2)/(Km1+P2);
A3 = (Vm5*E2)/(Km5+E2);
A4 = (Vm6*A2)/(Km6+A2);
A7 = (Vm7*A6)/(Km7+A6);
B3 = (Vm8*F2)/(Km8+F2);
C3 = (Vm9*B2)/(Km9+B2);
D3 = (Vm2*A2)/(Km2+A2);
D4 = (Vm4*D2)/(Km4+D2);
E3 = (Vm3*D2)/(Km3+D2);
E4 = (Vm10*E2)/(Km10+E2);
F3 = (Vm11*A2)/(Km11+A2);
if (A8>0) { P2 = P2-(Z*A8); }
if (A8>0) { A1 = ((A1*A2)+(P1*Z*A8))/(A2+(Z*A8)); }
if (A8>0) { A2 = A2+(Z*A8); }
if (A3>0) { A1 = ((A1*A2)+(E1*Z*A3))/(A2+(Z*A3)); }
if (A3>0) { A2 = A2+(Z*A3); }
if (A4>0) { A1 = ((A1*A2)-(A1*Z*A4))/(A2-(Z*A4)); }
if (A4>0) { A2 = A2-(Z*A4); }
if (A4>0) { A5 = ((A5*A6)+(A1*Z*A4))/(A6+(Z*A4)); }
if (A4>0) { A6 = A6+(Z*A4); }
if (A7>0) { A5 = ((A5*A6)-(A5*Z*A7))/(A6-(Z*A7)); }
if (A7>0) { A6 = A6-(Z*A7); }
if (A7>0) { A1 = ((A1*A2)+(A5*Z*A7))/(A2+(Z*A7)); }
if (A7>0) { A2 = A2+(Z*A7); }
if (D3>0) { A1 = ((A1*A2)-(A1*Z*D3))/(A2-(Z*D3)); }
if (D3>0) { A2 = A2-(Z*D3); }
if (F3>0) { A1 = ((A1*A2)-(A1*Z*F3))/(A2-(Z*F3)); }
if (F3>0) { A2 = A2-(Z*F3); }
if (F3>0) { F1 = ((F1*F2)+(A1*Z*F3))/(F2+(Z*F3)); }
if (F3>0) { F2 = F2+(Z*F3); }
if (B3>0) { F1 = ((F1*F2)-(F1*Z*B3))/(F2-(Z*B3)); }
if (B3>0) { F2 = F2-(Z*B3); }
if (B3>0) { B1 = ((B1*B2)+(F1*Z*B3))/(B2+(Z*B3)); }
if (B3>0) { B2 = B2+(Z*B3); }
if (C3>0) { B1 = ((B1*B2)-(B1*Z*C3))/(B2-(Z*C3)); }
if (C3>0) { B2 = B2-(Z*C3); }
if (C3>0) { C1 = ((C1*C2)+(B1*Z*C3))/(C2+(Z*C3)); }
if (C3>0) { C2 = C2+(Z*C3); }
if (D3>0) { D1 = ((D1*D2)+(A1*Z*D3))/(D2+(Z*D3)); }
if (D3>0) { D2 = D2+(Z*D3); }
if (D4>0) { D1 = ((D1*D2)-(D1*Z*D4))/(D2-(Z*D4)); }
if (D4>0) { D2 = D2-(Z*D4); }
if (D5>0) { D1 = ((D1*D2)+(G1*Z*D5))/(D2+(Z*D5)); }
if (D5>0) { D2 = D2+(Z*D5); }
if (E3>0) { D1 = ((D1*D2)-(D1*Z*E3))/(D2-(Z*E3)); }
if (E3>0) { D2 = D2-(Z*E3); }
if (E3>0) { E1 = ((E1*E2)+(D1*Z*E3))/(E2+(Z*E3)); }
if (E3>0) { E2 = E2+(Z*E3); }
if (E5>0) { E1 = ((E1*E2)+(G1*Z*E5))/(E2+(Z*E5)); }
if (E5>0) { E2 = E2+(Z*E5); }
if (A3>0) { E1 = ((E1*E2)-(E1*Z*A3))/(E2-(Z*A3)); }
if (A3>0) { E2 = E2-(Z*A3); }
if (E4>0) { E1 = ((E1*E2)-(E1*Z*E4))/(E2-(Z*E4)); }
if (E4>0) { E2 = E2-(Z*E4); }
if (D4>0) { A1 = ((A1*A2)+(D1*Z*D4))/(A2+(Z*D4)); }
if (D4>0) { A2 = A2+(Z*D4); }
if (E4>0) { D1 = ((D1*D2)+(E1*Z*E4))/(D2+(Z*E4)); }
if (E4>0) { D2 = D2+(Z*E4); }

if (P2<0) { break; }
if (A2<0) { break; }
if (A6<0) { break; }
if (B2<0) { break; }
if (C2<0) { break; }
if (D2<0) { break; }
if (E2<0) { break; }
if (F2<0) { break; }

isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((P1*P2) / Y1) * GraphSize)), Color.black, 1, 1);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((((A1*A2)+(A5*A6)+(F1*F2)) / Y1) * GraphSize)), Color.green, 1, 1);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((B1*B2) / (Y1*BS)) * GraphSize)), Color.cyan, 1, 1);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((C1*C2) / (Y1*CS)) * GraphSize)), Color.blue, 1, 1);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((D1*D2) / Y1) * GraphSize)), Color.red, 1, 1);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((E1*E2) / Y1) * GraphSize)), Color.magenta, 1, 1);

poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((P2 / Y2) * GraphSize)), Color.black, 1, 1);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((A2+A6+F2) / Y2) * GraphSize)), Color.green, 1, 1);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((B2 / (Y2*BS)) * GraphSize)), Color.cyan, 1, 1);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((C2 / Y2) * GraphSize)), Color.blue, 1, 1);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((D2 / Y2) * GraphSize)), Color.red, 1, 1);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((E2 / (Y2*ES)) * GraphSize)), Color.magenta, 1, 1);

//add error checking re: P2, A2, B2, C2, D2, E2, A6 < 0
}

isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((15 / TS) * GraphSize), GraphSize - ((int) ((7868 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((6864 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((2868 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((762 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((300 / TS) * GraphSize), GraphSize - ((int) ((1538 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((600 / TS) * GraphSize), GraphSize - ((int) ((730 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((15 / TS) * GraphSize), GraphSize - ((int) ((866 / Y1) * GraphSize)), Color.red, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((1636 / Y1) * GraphSize)), Color.red, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((4794 / Y1) * GraphSize)), Color.red, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((3236 / Y1) * GraphSize)), Color.red, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((300 / TS) * GraphSize), GraphSize - ((int) ((202 / Y1) * GraphSize)), Color.red, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((600 / TS) * GraphSize), GraphSize - ((int) ((202 / Y1) * GraphSize)), Color.red, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((15 / TS) * GraphSize), GraphSize - ((int) ((454 / Y1) * GraphSize)), Color.magenta, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((688 / Y1) * GraphSize)), Color.magenta, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((1568 / Y1) * GraphSize)), Color.magenta, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((5140 / Y1) * GraphSize)), Color.magenta, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((300 / TS) * GraphSize), GraphSize - ((int) ((7434 / Y1) * GraphSize)), Color.magenta, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((600 / TS) * GraphSize), GraphSize - ((int) ((8240 / Y1) * GraphSize)), Color.magenta, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((15 / TS) * GraphSize), GraphSize - ((int) ((6.2 / (Y1*CS)) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((10 / (Y1*CS)) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((2 / (Y1*CS)) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((44.8 / (Y1*CS)) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((300 / TS) * GraphSize), GraphSize - ((int) ((50.8 / (Y1*CS)) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((600 / TS) * GraphSize), GraphSize - ((int) ((57.6 / (Y1*CS)) * GraphSize)), Color.blue, 5, 5);


isotopeGraph.repaint();
poolGraph.repaint();
bDoGraph.enable();
repaint();

}




float floatFromTextField (TextField tf) {
String s;
float value;

s = tf.getText();

try {
value = Float.valueOf(s).floatValue();
} catch (Exception e) {
value = (float) 0.0;
}
return value;
}

Image blankGraph (int width, int height) {
Image tempImage;
Graphics tempGr;

tempImage = createImage(width, height);
tempGr = tempImage.getGraphics();



// draw a box around the graph
tempGr.setColor (Color.white);
tempGr.fillRect (0, 0, width, height);
tempGr.setColor (Color.black);
tempGr.drawRect (0, 0, width - 1, height - 1);
// draw ticks marks around edges
int i;
int hinterval = width / 5;
int vinterval = height / 5;
int TickLength = 2;
for (i = 0; i < 4; i++) {
tempGr.drawLine (hinterval * (i + 1), 0, hinterval * (i + 1), TickLength);
tempGr.drawLine (0, vinterval * (i + 1), TickLength, vinterval * (i + 1));
tempGr.drawLine (width - TickLength - 1, hinterval * (i + 1), height - 1, vinterval * (i + 1));
tempGr.drawLine (hinterval * (i + 1), height - TickLength - 1, hinterval * (i + 1), height);
}

return (tempImage);
}


Image addPoint (Image tempImage, int x, int y, Color pointColor, int size1, int size2) {
Graphics tempGr;

tempGr = tempImage.getGraphics();
tempGr.setColor (pointColor);
tempGr.fillRect (x, y, size1, size2);

return (tempImage);
}

}
class Graph extends Canvas {
public Image graphImage;
public int width;
public int height;
public Dimension preferredSize() {
return new Dimension (width, height);
}

Graph (int width, int height) {
this.width = width;
this.height = height;
resize(preferredSize());
}

public void update (Graphics g) { paint(g); }

public void paint (Graphics g) {
g.drawImage (graphImage, 0, 0, this);
}
}	