// interact.java // two populations with competitive interactions // adapted from a program in basic by H.T. Odum & E. Odum, 1994 import java.applet.*; import java.awt.*; public class interact extends Applet { Label prompt1, prompt2, prompt3; TextField input1, input2, input3; Button drawbutton; double E, Q1, Q1i, Q2, Q2i, D1, D2, K1, K2, K3, K4, K5, K6, t, ti; public void init() { drawbutton = new Button("Draw"); add(drawbutton); prompt1 = new Label("E Energy concentration: "); input1 = new TextField("100", 5); add(prompt1); add(input1); prompt2 = new Label("K5 first interaction coefficient: "); input2 = new TextField("2", 5); add(prompt2); add(input2); prompt3 = new Label("K6 second interaction coefficient: "); input3 = new TextField("1", 5); add(prompt3); add(input3); } public boolean action(Event e, Object o) { E = (float)Integer.parseInt(input1.getText()); K5 = (float)Integer.parseInt(input2.getText()); K6 = (float)Integer.parseInt(input3.getText()); repaint(); return true; } public void paint(Graphics g) { g.drawRect(0,90,320,180); t=0; E=E/100; K1=0.07f; K2=0.08f; K3=0.002f; K4=0.001f; K5=K5/1000; K6=K6/1000; Q1=3;Q2=3; while (t<320) { ti=t+1; D1=K1*E*Q1-K3*Q1*Q1-K5*Q1*Q2; D2=K2*E*Q2-K4*Q2*Q2-K6*Q1*Q2; Q1i=Q1+D1; Q2i=Q2+D2; g.setColor(Color.blue); g.drawLine((int)t, (int)(270-Q1), (int)ti, (int)(270-Q1i)); g.setColor(Color.green); g.drawLine((int)t, (int)(270-Q2), (int)ti, (int)(270-Q2i)); t=ti; Q1=Q1i; Q2=Q2i; } } } // Manuel Basler & E. Ortega, October 17th 2000*/