/*
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, textM1;
TextField  textB1, textB2, textB3, textB4;
TextField  textC1, textC2, textC3, textC4; 
TextField  textD1, textD2, textD3;
TextField  textE1, textE2, textE3;
TextField  textF1, textF2, textF3;
TextField  textG1, textG2, textG3;
TextField  textTS;
TextField  textTC;
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 labelA1 = new Label("A1:");
textA1 = new TextField("3125", 6);
Label labelA2 = new Label("A2:");
textA2 = new TextField("1.6", 6);
Label labelB1 = new Label("B1:");
textB1 = new TextField("0", 6);
Label labelB2 = new Label("B2:");
textB2 = new TextField("0.2", 6);
Label labelB3 = new Label("B3:");
textB3 = new TextField("0.032", 6);
Label labelB4 = new Label("B4:");
textB4 = new TextField("0.029", 6);
Label labelC1 = new Label("C1:");
textC1 = new TextField("0", 6);
Label labelM1 = new Label("M1:");
textM1 = new TextField("0", 6);
Label labelC2 = new Label("C2:");
textC2 = new TextField("330", 6);
Label labelC3 = new Label("C3:");
textC3 = new TextField("0.003", 6);
Label labelC4 = new Label("C4:");
textC4 = new TextField("2.7", 6);
Label labelD1 = new Label("D1:");
textD1 = new TextField("0", 6);
Label labelD2 = new Label("D2:");
textD2 = new TextField("150", 6);
Label labelD3 = new Label("D3:");
textD3 = new TextField("0.45", 6);
Label labelE1 = new Label("E1:");
textE1 = new TextField("0", 6);
Label labelE2 = new Label("E2:");
textE2 = new TextField("20", 6);
Label labelE3 = new Label("E3:");
textE3 = new TextField("2.7", 6);
Label labelF1 = new Label("F1:");
textF1 = new TextField("0", 6);
Label labelF2 = new Label("F2:");
textF2 = new TextField("14", 6);
Label labelF3 = new Label("F3:");
textF3 = new TextField("0.1", 6);
Label labelG1 = new Label("G1:");
textG1 = new TextField("0", 6);
Label labelG2 = new Label("G2:");
textG2 = new TextField("27500", 6);
Label labelG3 = new Label("G3:");
textG3 = new TextField("2.7", 6);
Label labelTS = new Label("TS:");
textTS = new TextField("600.0", 6);
Label labelTC = new Label("TC:");
textTC = new TextField("150", 6);
Label labelML = new Label("ML:");
textMy1 = new TextField("1500.0", 6);
Label labelMR = new Label("MR:");
textMy2 = new TextField("60.00", 6);
Label gLabel1 = new Label("Radioactivity: SMM, DMSP");
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: DA");
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(labelA1,  gbc);
add(labelA1);
gbc.gridy = 1;
gb.setConstraints(labelA2,  gbc);
add(labelA2);
gbc.gridy = 2;
gb.setConstraints(labelB1,  gbc);
add(labelB1);
gbc.gridy = 3;
gb.setConstraints(labelB2,  gbc);
add(labelB2);
gbc.gridy = 4;
gb.setConstraints(labelB3,  gbc);
add(labelB3);
gbc.gridy = 5;
gb.setConstraints(labelB4,  gbc);
add(labelB4);

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(textA1,  gbc);
add(textA1);
gbc.gridy = 1;
gb.setConstraints(textA2,  gbc);
add(textA2);
gbc.gridy = 2;
gb.setConstraints(textB1,  gbc);
add(textB1);
gbc.gridy = 3;
gb.setConstraints(textB2,  gbc);
add(textB2);
gbc.gridy = 4;
gb.setConstraints(textB3,  gbc);
add(textB3);
gbc.gridy = 5;
gb.setConstraints(textB4,  gbc);
add(textB4);

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(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(labelD1,  gbc);
add(labelD1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelD2,  gbc);
add(labelD2);

gbc.gridy = 13;
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(textC3,  gbc);
add(textC3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textC4,  gbc);
add(textC4);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD1,  gbc);
add(textD1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textD2,  gbc);
add(textD2);

gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = 0;
gb.setConstraints(labelD3,  gbc);
add(labelD3);
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(labelE3,  gbc);
add(labelE3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelF1,  gbc);
add(labelF1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelF2,  gbc);
add(labelF2);

gbc = new GridBagConstraints();
gbc.gridx = 5;
gbc.gridy = 0;
gb.setConstraints(textD3,  gbc);
add(textD3);
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(textE3,  gbc);
add(textE3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textF1,  gbc);
add(textF1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textF2,  gbc);
add(textF2);

gbc.gridy = 13;
gbc.anchor = GridBagConstraints.NORTHEAST;
gb.setConstraints(endXAxis1,  gbc);
add(endXAxis1);

gbc = new GridBagConstraints();
gbc.gridx = 6;
gbc.gridy = 0;
gb.setConstraints(labelF3,  gbc);
add(labelF3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelG1,  gbc);
add(labelG1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelG2,  gbc);
add(labelG2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelG3,  gbc);
add(labelG3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelM1,  gbc);
add(labelM1);

gbc = new GridBagConstraints();
gbc.gridx = 7;
gbc.gridy = 0;
gb.setConstraints(textF3,  gbc);
add(textF3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textG1,  gbc);
add(textG1);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textG2,  gbc);
add(textG2);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textG3,  gbc);
add(textG3);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textM1,  gbc);
add(textM1);

gbc = new GridBagConstraints();
gbc.gridx = 8;
gbc.gridy = 0;
gb.setConstraints(labelTS,  gbc);
add(labelTS);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(labelTC,  gbc);
add(labelTC);
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(textTS,  gbc);
add(textTS);
gbc.gridy = GridBagConstraints.RELATIVE;
gb.setConstraints(textTC,  gbc);
add(textTC);
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 M1 = floatFromTextField(textM1);
float A1 = floatFromTextField(textA1);
float A2 = floatFromTextField(textA2);
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 D1 = floatFromTextField(textD1);
float D2 = floatFromTextField(textD2);
float D3 = floatFromTextField(textD3);
float E1 = floatFromTextField(textE1);
float E2 = floatFromTextField(textE2);
float E3 = floatFromTextField(textE3);
float F1 = floatFromTextField(textF1);
float F2 = floatFromTextField(textF2);
float F3 = floatFromTextField(textF3);
float G1 = floatFromTextField(textG1);
float G2 = floatFromTextField(textG2);
float G3 = floatFromTextField(textG3);

float TS = floatFromTextField(textTS);
float TC = floatFromTextField(textTC);
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 t;
float Z = TS / 2500;
for (t=0; t <= TS; t = t + Z) {
if (t>TC) { A1 = 0; }
if (t>TC) { A2 = 0; }
if (B3>0) { A1 = ((A1*A2)-(A1*Z*B3))/(A2-(Z*B3)); }
if (B3>0) { A2 = A2-(Z*B3); }
if (B4>0) { A1 = ((A1*A2)+(B1*Z*B4))/(A2+(Z*B4)); }
if (B4>0) { A2 = A2+(Z*B4); }
if (B3>0) { B1 = ((B1*B2)+(A1*Z*B3))/(B2+(Z*B3)); }
if (B3>0) { B2 = B2+(Z*B3); }
if (B4>0) { B1 = ((B1*B2)-(B1*Z*B4))/(B2-(Z*B4)); }
if (B4>0) { B2 = B2-(Z*B4); }
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 (C4>0) { C1 = ((C1*C2)+(M1*Z*C4))/(C2+(Z*C4)); }
if (C4>0) { C2 = C2+(Z*C4); }
if (E3>0) { C1 = ((C1*C2)-(C1*Z*E3))/(C2-(Z*E3)); }
if (E3>0) { C2 = C2-(Z*E3); }
if (D3>0) { D1 = ((D1*D2)+(C1*Z*D3))/(D2+(Z*D3)); }
if (D3>0) { D2 = D2+(Z*D3); }
if (D3>0) { D1 = ((D1*D2)-(D1*Z*D3))/(D2-(Z*D3)); }
if (D3>0) { D2 = D2-(Z*D3); }
if (D3>0) { C1 = ((C1*C2)+(C1*Z*D3))/(C2+(Z*D3)); }
if (D3>0) { C2 = C2+(Z*D3); }
if (D3>0) { C1 = ((C1*C2)-(C1*Z*D3))/(C2-(Z*D3)); }
if (D3>0) { C2 = C2-(Z*D3); }
if (E3>0) { E1 = ((E1*E2)+(C1*Z*E3))/(E2+(Z*E3)); }
if (E3>0) { E2 = E2+(Z*E3); }
if (G3>0) { E1 = ((E1*E2)-(E1*Z*G3))/(E2-(Z*G3)); }
if (G3>0) { E2 = E2-(Z*G3); }
if (F3>0) { F1 = ((F1*F2)+(E1*Z*F3))/(F2+(Z*F3)); }
if (F3>0) { F2 = F2+(Z*F3); }
if (F3>0) { F1 = ((F1*F2)-(F1*Z*F3))/(F2-(Z*F3)); }
if (F3>0) { F2 = F2-(Z*F3); }
if (F3>0) { E1 = ((E1*E2)+(F1*Z*F3))/(E2+(Z*F3)); }
if (F3>0) { E2 = E2+(Z*F3); }
if (F3>0) { E1 = ((E1*E2)-(E1*Z*F3))/(E2-(Z*F3)); }
if (F3>0) { E2 = E2-(Z*F3); }
if (G3>0) { G1 = ((G1*G2)+(E1*Z*G3))/(G2+(Z*G3)); }
if (G3>0) { G2 = G2+(Z*G3); }

if (C2<0) { break; }
if (D2<0) { break; }
if (E2<0) { break; }
if (F2<0) { break; }
if (G2<0) { break; }

isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((((B1*B2)+(C1*C2)+(D1*D2)) / Y1) * GraphSize)), Color.blue, 1, 1);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) (((G1*G2) / Y1) * GraphSize)), Color.orange, 1, 1);

poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((t / TS) * GraphSize), GraphSize - ((int) ((((E1*E2)+(F1*F2)) / Y2) * GraphSize)), Color.red, 1, 1);

//add error checking re: B2, C2, D2, E2, F2, G2 < 0
}

isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((417 / Y1) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((500 / Y1) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((20 / TS) * GraphSize), GraphSize - ((int) ((627 / Y1) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((40 / TS) * GraphSize), GraphSize - ((int) ((816 / Y1) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((90 / TS) * GraphSize), GraphSize - ((int) ((1057 / Y1) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((150 / TS) * GraphSize), GraphSize - ((int) ((1340 / Y1) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((210 / TS) * GraphSize), GraphSize - ((int) ((549 / Y1) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((330 / TS) * GraphSize), GraphSize - ((int) ((242 / Y1) * GraphSize)), Color.blue, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((510 / TS) * GraphSize), GraphSize - ((int) ((97 / Y1) * GraphSize)), Color.blue, 5, 5);

isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((0.05 / Y1) * GraphSize)), Color.orange, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((0.7 / Y1) * GraphSize)), Color.orange, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((20 / TS) * GraphSize), GraphSize - ((int) ((5.6 / Y1) * GraphSize)), Color.orange, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((40 / TS) * GraphSize), GraphSize - ((int) ((33.4 / Y1) * GraphSize)), Color.orange, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((90 / TS) * GraphSize), GraphSize - ((int) ((190 / Y1) * GraphSize)), Color.orange, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((150 / TS) * GraphSize), GraphSize - ((int) ((552 / Y1) * GraphSize)), Color.orange, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((210 / TS) * GraphSize), GraphSize - ((int) ((703 / Y1) * GraphSize)), Color.orange, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((330 / TS) * GraphSize), GraphSize - ((int) ((969 / Y1) * GraphSize)), Color.orange, 5, 5);
isotopeGraph.graphImage = addPoint(isotopeGraph.graphImage, (int) ((510 / TS) * GraphSize), GraphSize - ((int) ((1021 / Y1) * GraphSize)), Color.orange, 5, 5);

poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((5 / TS) * GraphSize), GraphSize - ((int) ((0.2 / Y2) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((10 / TS) * GraphSize), GraphSize - ((int) ((2.2 / Y2) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((20 / TS) * GraphSize), GraphSize - ((int) ((4.0 / Y2) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((40 / TS) * GraphSize), GraphSize - ((int) ((11.6 / Y2) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((90 / TS) * GraphSize), GraphSize - ((int) ((29.8 / Y2) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((150 / TS) * GraphSize), GraphSize - ((int) ((49.4 / Y2) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((210 / TS) * GraphSize), GraphSize - ((int) ((43.4 / Y2) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((330 / TS) * GraphSize), GraphSize - ((int) ((20.2 / Y2) * GraphSize)), Color.red, 5, 5);
poolGraph.graphImage = addPoint(poolGraph.graphImage, (int) ((510 / TS) * GraphSize), GraphSize - ((int) ((13.2 / Y2) * GraphSize)), Color.red, 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);
}
}	