/*
To do Rhodes' modeling - 7/98 EFG
Interface tweaking - 10/98 EFG
Modified - 01/99 DR
*/

import java.awt.*;
import java.applet.Applet;

public class model extends Applet
{
TextField  textA1, textA2, textA3, textA7;
TextField  textF1, textB1, textB2, textB3, textB4;
TextField  textP1, textP2, textP3, textC1, textC2, textC3, textC4, textC5, textC6; 
TextField  textD1, textD2, textD3, textD4, textD5, textD6, textk;
TextField  textE1, textE2, textE3;
TextField  textTS;
TextField  textCS;
TextField  textDS;
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("10000", 6);
Label labelP2 = new Label("P2:");
textP2 = new TextField("4.57", 6);
Label labelP3 = new Label("P3:");
textP3 = new TextField("0.43", 6);
Label labelA1 = new Label("A1:");
textA1 = new TextField("0", 6);
Label labelA2 = new Label("A2:");
textA2 = new TextField("14", 6);
Label labelA3 = new Label("A3:");
textA3 = new TextField("0.08", 6);
Label labelA7 = new Label("A7:");
textA7 = new TextField("0.01", 6);
Label labelF1 = new Label("F1:");
textF1 = new TextField("0", 6);
Label labelB1 = new Label("B1:");
textB1 = new TextField("0", 6);
Label labelB2 = new Label("B2:");
textB2 = new TextField("900", 6);
Label labelB3 = new Label("B3:");
textB3 = new TextField("0.14", 6);
Label labelB4 = new Label("B4:");
textB4 = new TextField("0.14", 6);
Label labelC1 = new Label("C1:");
textC1 = new TextField("0", 6);
Label labelC2 = new Label("C2:");
textC2 = new TextField("0.03", 6);
Label labelC3 = new Label("C3:");
textC3 = new TextField("0.07", 6);
Label labelC4 = new Label("C4:");
textC4 = new TextField("0.0008", 6);
Label labelC5 = new Label("C5:");
textC5 = new TextField("0", 6);
Label labelC6 = new Label("C6:");
textC6 = new TextField("0.08", 6);
Label labelD1 = new Label("D1:");
textD1 = new TextField("0", 6);
Label labelD2 = new Label("D2:");
textD2 = new TextField("0.40", 6);
Label labelD3 = new Label("D3:");
textD3 = new TextField("0.07", 6);
Label labelD4 = new Label("D4:");
textD4 = new TextField("0.02", 6);
Label labelD5 = new Label("D5:");
textD5 = new TextField("0", 6);
Label labelD6 = new Label("D6:");
textD6 = new TextField("4.0", 6);
Label labelE1 = new Label("E1:");
textE1 = new TextField("0", 6);
Label labelE2 = new Label("E2:");
textE2 = new TextField("20000", 6);
Label labelE3 = new Label("E3:");
textE3 = new TextField("0.07", 6);
Label labelk = new Label("k:");
textk = new TextField("0.287", 6);
Label labelTS = new Label("TS:");
textTS = new TextField("1200", 6);
Label labelCS = new Label("CS:");
textCS = new TextField("0.01", 6);
Label labelDS = new Label("DS:");
textDS = new TextField("0.125", 6);
Label labelML = new Label("ML:");
textMy1 = new TextField("50000", 6);
Label labelMR = new Label("MR:");
textMy2 = new TextField("15000", 6);
Label gLabel1 = new Label("Radioactivity");
Label xLabel1 = new Label("Time (min)");
Label yLabel1 = new Label("nCi.gfw(-1)");
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("Radioactivity");
Label xLabel2 = new Label("Time (min)");
Label yLabel2 = new Label("nCi.gfw(-1)");
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(labelP3,  gbc);
add(labelP3);
gbc.gridy = 3;
gb.setConstraints(labelTS,  gbc);
add(labelTS);
gbc.gridy = 4;
gb.setConstraints(labelk,  gbc);
add(labelk);
gbc.gridy = 5;
gb.setConstraints(labelF1,  gbc);
add(labelF1);
gbc.gridy = 6;
gb.setConstraints(labelA1,  gbc);
add(labelA1);

gbc.gridy = 8;
gbc.anchor = GridBagConstraints.NORTHEAST;
gb.setConstraints(endYAxis1,  gbc);
add(endYAxis1);
gbc.gridy = 10;
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridheight = 3;
gb.setConstraints(yLabel1,  gbc);
add(yLabel1);
gbc.gridy = 12;
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(textP3,  gbc);
add(textP3);
gbc.gridy = 3;
gb.setConstraints(textTS,  gbc);
add(textTS);
gbc.gridy = 4;
gb.setConstraints(textk,  gbc);
add(textk);
gbc.gridy = 5;
gb.setConstraints(textF1,  gbc);
add(textF1);
gbc.gridy = 6;
gb.setConstraints(textA1,  gbc);
add(textA1);

gbc.gridy = 7;
gbc.gridwidth = 5;
gb.setConstraints(gLabel1,  gbc);
add(gLabel1);
gbc.gridy = 8;
gbc.gridheight = 5;
gb.setConstraints(isotopeGraph,  gbc);
add(isotopeGraph);
gbc.gridy = 13;
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(labelA2,  gbc);
add(labelA2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelA3,  gbc);
add(labelA3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelA7,  gbc);
add(labelA7);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelB1,  gbc);
add(labelB1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelB2,  gbc);
add(labelB2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelB3,  gbc);
add(labelB3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelB4,  gbc);
add(labelB4);

gbc.gridy = 13;
gbc.gridwidth = 3;
gb.setConstraints(xLabel1,  gbc);
add(xLabel1);

gbc = new GridBagConstraints();
gbc.gridx = 3;
gbc.gridy = 0;
gb.setConstraints(textA2,  gbc);
add(textA2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textA3,  gbc);
add(textA3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textA7,  gbc);
add(textA7);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textB1,  gbc);
add(textB1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textB2,  gbc);
add(textB2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textB3,  gbc);
add(textB3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textB4,  gbc);
add(textB4);

gbc = new GridBagConstraints();
gbc.gridx = 4;
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(labelC3,  gbc);
add(labelC3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelC4,  gbc);
add(labelC4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelC5,  gbc);
add(labelC5);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelC6,  gbc);
add(labelC6);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelCS,  gbc);
add(labelCS);

gbc = new GridBagConstraints();
gbc.gridx = 5;
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(textC3,  gbc);
add(textC3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textC4,  gbc);
add(textC4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textC5,  gbc);
add(textC5);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textC6,  gbc);
add(textC6);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textCS,  gbc);
add(textCS);

gbc.gridy = 13;
gbc.anchor = GridBagConstraints.NORTHEAST;
gb.setConstraints(endXAxis1,  gbc);
add(endXAxis1);

gbc = new GridBagConstraints();
gbc.gridx = 6;
gbc.gridy = 0;
gb.setConstraints(labelD1,  gbc);
add(labelD1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD2,  gbc);
add(labelD2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD3,  gbc);
add(labelD3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD4,  gbc);
add(labelD4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD5,  gbc);
add(labelD5);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD6,  gbc);
add(labelD6);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelDS,  gbc);
add(labelDS);

gbc = new GridBagConstraints();
gbc.gridx = 7;
gbc.gridy = 0;
gb.setConstraints(textD1,  gbc);
add(textD1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD2,  gbc);
add(textD2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD3,  gbc);
add(textD3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD4,  gbc);
add(textD4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD5,  gbc);
add(textD5);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD6,  gbc);
add(textD6);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textDS,  gbc);
add(textDS);

gbc = new GridBagConstraints();
gbc.gridx = 8;
gbc.gridy = 0;
gb.setConstraints(labelE1,  gbc);
add(labelE1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelE2,  gbc);
add(labelE2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelE3,  gbc);
add(labelE3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelML,  gbc);
add(labelML);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelMR,  gbc);
add(labelMR);

gbc.gridy = 8;
gbc.anchor = GridBagConstraints.NORTHEAST;
gb.setConstraints(endYAxis2,  gbc);
add(endYAxis2);
gbc.gridy = 10;
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridheight = 3;
gb.setConstraints(yLabel2,  gbc);
add(yLabel2);
gbc.gridheight = 1;
gbc.gridy = 12;
gbc.anchor = GridBagConstraints.SOUTHEAST;
gb.setConstraints(startYAxis2,  gbc);
add(startYAxis2);

gbc = new GridBagConstraints();
gbc.gridx = 9;
gbc.gridy = 0;
gb.setConstraints(textE1,  gbc);
add(textE1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textE2,  gbc);
add(textE2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textE3,  gbc);
add(textE3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textMy1,  gbc);
add(textMy1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textMy2,  gbc);
add(textMy2);

gbc.gridy = 7;
gbc.gridwidth = 5;
gb.setConstraints(gLabel2,  gbc);
add(gLabel2);
gbc.gridy = 8;
gbc.gridheight = 5;
gb.setConstraints(poolGraph,  gbc);
add(poolGraph);
gbc.gridy = 13;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
gb.setConstraints(startXAxis2,  gbc);
add(startXAxis2);

gbc = new GridBagConstraints();
gbc.gridx = 10;
gbc.gridy = 13;
gbc.gridwidth = 3;
gb.setConstraints(xLabel2,  gbc);
add(xLabel2);

gbc.gridx = 6;
gbc.gridy = 11;
gbc.gridwidth = 1;
gb.setConstraints(bDoGraph,  gbc);
add(bDoGraph);

gbc.gridx = 13;
gbc.gridy = 13;
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 P3 = floatFromTextField(textP3);
float A1 = floatFromTextField(textA1);
float A2 = floatFromTextField(textA2);
float A3 = floatFromTextField(textA3);
float A7 = floatFromTextField(textA7);
float B1 = floatFromTextField(textB1);
float B2 = floatFromTextField(textB2);
float B3 = floatFromTextField(textB3);
float B4 = floatFromTextField(textB4);
float C1 = floatFromTextField(textC1);
float C2 = floatFromTextField(textC2);
float C3 = floatFromTextField(textC3);
float C4 = floatFromTextField(textC4);
float C5 = floatFromTextField(textC5);
float C6 = floatFromTextField(textC6);
float D1 = floatFromTextField(textD1);
float D2 = floatFromTextField(textD2);
float D3 = floatFromTextField(textD3);
float D4 = floatFromTextField(textD4);
float D5 = floatFromTextField(textD5);
float D6 = floatFromTextField(textD6);
float E1 = floatFromTextField(textE1);
float E2 = floatFromTextField(textE2);
float E3 = floatFromTextField(textE3);
float F1 = floatFromTextField(textF1);
float k = floatFromTextField(textk);
float TS = floatFromTextField(textTS);
float CS = floatFromTextField(textCS);
float DS = floatFromTextField(textDS);
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 t;
float Z = TS / 2400;
for (t=0; t <= TS; t = t + Z) {
A8 = P2*k;
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)+(F1*Z*A3))/(A2+(Z*A3)); }
if (A3>0) { A2 = A2+(Z*A3); }
if (C3>0) { A1 = ((A1*A2)-(A1*Z*C3))/(A2-(Z*C3)); }
if (C3>0) { A2 = A2-(Z*C3); }
if (B3>0) { A1 = ((A1*A2)-(A1*Z*(B3+A8)))/(A2-(Z*(B3+A8))); }
if (B3>0) { A2 = A2-(Z*(B3+A8)); }
if (A7>0) { A1 = ((A1*A2)-(A1*Z*A7))/(A2-(Z*A7)); }
if (A7>0) { A2 = A2-(Z*A7); }
if (B3>0) { B1 = ((B1*B2)+(A1*Z*(B3+A8)))/(B2+(Z*(B3+A8))); }
if (B3>0) { B2 = B2+(Z*(B3+A8)); }
if (B4>0) { B1 = ((B1*B2)-(B1*Z*B4))/(B2-(Z*B4)); }
if (B4>0) { B2 = B2-(Z*B4); }
if (B4>0) { A1 = ((A1*A2)+(B1*Z*B4))/(A2+(Z*B4)); }
if (B4>0) { A2 = A2+(Z*B4); }
if (C3>0) { C1 = ((C1*C2)+(A1*Z*C3))/(C2+(Z*C3)); }
if (C3>0) { C2 = C2+(Z*C3); }
if (C4>0) { C1 = ((C1*C2)-(C1*Z*C4))/(C2-(Z*C4)); }
if (C4>0) { C2 = C2-(Z*C4); }
if (D3>0) { C1 = ((C1*C2)-(C1*Z*D3))/(C2-(Z*D3)); }
if (D3>0) { C2 = C2-(Z*D3); }
if (C4>0) { C5 = ((C5*C6)+(C1*Z*C4))/(C6+(Z*C4)); }
if (C4>0) { C6 = C6+(Z*C4); }
if (C4>0) { C5 = ((C5*C6)-(C5*Z*C4))/(C6-(Z*C4)); }
if (C4>0) { C6 = C6-(Z*C4); }
if (C4>0) { C1 = ((C1*C2)+(C5*Z*C4))/(C2+(Z*C4)); }
if (C4>0) { C2 = C2+(Z*C4); }
if (D3>0) { D1 = ((D1*D2)+(C1*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 (E3>0) { D1 = ((D1*D2)-(D1*Z*E3))/(D2-(Z*E3)); }
if (E3>0) { D2 = D2-(Z*E3); }
if (D4>0) { D5 = ((D5*D6)+(D1*Z*D4))/(D6+(Z*D4)); }
if (D4>0) { D6 = D6+(Z*D4); }
if (D4>0) { D5 = ((D5*D6)-(D5*Z*D4))/(D6-(Z*D4)); }
if (D4>0) { D6 = D6-(Z*D4); }
if (D4>0) { D1 = ((D1*D2)+(D5*Z*D4))/(D2+(Z*D4)); }
if (D4>0) { D2 = D2+(Z*D4); }
if (E3>0) { E1 = ((E1*E2)+(D1*Z*E3))/(E2+(Z*E3)); }
if (E3>0) { E2 = E2+(Z*E3); }

if (P2<0) { break; }
if (A2<0) { break; }
if (B2<0) { break; }
if (C2<0) { break; }
if (D2<0) { break; }
if (E2<0) { break; }
if (C6<0) { break; }
if (D6<0) { break; }

isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((((P1*P2)+(P1*P3)) / Y1) * GraphSize)), Color.black, 1, 1);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((A1*A2) / Y1) * GraphSize)), Color.green, 1, 1);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((B1*B2) / Y1) * GraphSize)), Color.yellow, 1, 1);

poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((((C1*C2)+(C5*C6)) / (Y2*CS))) * GraphSize)), Color.blue, 1, 1);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((((D1*D2)+(D5*D6)) / (Y2*DS))) * GraphSize)), Color.red, 1, 1);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((E1*E2) / Y2) * GraphSize)), Color.orange, 1, 1);

//add error checking re: P2, A2, B2, C2, D2, E2, C6, D6 < 0
}

isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((12990 / Y1) * GraphSize)), Color.black, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((5660 / Y1) * GraphSize)), Color.black, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((3510 / Y1) * GraphSize)), Color.black, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((4240 / Y1) * GraphSize)), Color.black, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((4130 / Y1) * GraphSize)), Color.black, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((240 / TS) * GraphSize), GraphSize - ((int) ((5150 / Y1) * GraphSize)), Color.black, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((1080 / TS) * GraphSize), GraphSize - ((int) ((6470 / Y1) * GraphSize)), Color.black, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((20920 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((28170 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((28850 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((15120 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((7100 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((240 / TS) * GraphSize), GraphSize - ((int) ((1930 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((1080 / TS) * GraphSize), GraphSize - ((int) ((350 / Y1) * GraphSize)), Color.green, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((5560 / Y1) * GraphSize)), Color.yellow, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((10200 / Y1) * GraphSize)), Color.yellow, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((14270 / Y1) * GraphSize)), Color.yellow, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((21200 / Y1) * GraphSize)), Color.yellow, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((27620 / Y1) * GraphSize)), Color.yellow, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((240 / TS) * GraphSize), GraphSize - ((int) ((30380 / Y1) * GraphSize)), Color.yellow, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((1080 / TS) * GraphSize), GraphSize - ((int) ((27560 / Y1) * GraphSize)), Color.yellow, 5, 5);

poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((69 / (Y2*CS)) * GraphSize)), Color.blue, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((130 / (Y2*CS)) * GraphSize)), Color.blue, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((97 / (Y2*CS)) * GraphSize)), Color.blue, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((91 / (Y2*CS)) * GraphSize)), Color.blue, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((68 / (Y2*CS)) * GraphSize)), Color.blue, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((240 / TS) * GraphSize), GraphSize - ((int) ((26 / (Y2*CS)) * GraphSize)), Color.blue, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((1080 / TS) * GraphSize), GraphSize - ((int) ((0 / (Y2*CS)) * GraphSize)), Color.blue, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((720 / (Y2*DS)) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((1100 / (Y2*DS)) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((1200 / (Y2*DS)) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((1780 / (Y2*DS)) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((1540 / (Y2*DS)) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((240 / TS) * GraphSize), GraphSize - ((int) ((1450 / (Y2*DS)) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((1080 / TS) * GraphSize), GraphSize - ((int) ((190 / (Y2*DS)) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((430 / Y2) * GraphSize)), Color.orange, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((990 / Y2) * GraphSize)), Color.orange, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((30 / TS) * GraphSize), GraphSize - ((int) ((1790 / Y2) * GraphSize)), Color.orange, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((60 / TS) * GraphSize), GraphSize - ((int) ((6460 / Y2) * GraphSize)), Color.orange, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((120 / TS) * GraphSize), GraphSize - ((int) ((6230 / Y2) * GraphSize)), Color.orange, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((240 / TS) * GraphSize), GraphSize - ((int) ((9800 / Y2) * GraphSize)), Color.orange, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((1080 / TS) * GraphSize), GraphSize - ((int) ((13670 / Y2) * GraphSize)), Color.orange, 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);
}
}	