// oscillat.java // Prey-Predator Oscillation // (a) constant force source // (b) renewable source // adapted from a program in basic by H.T. Odum & E. Odum, 1994 import java.applet.*; import java.awt.*; public class oscillat extends Applet { float ej, c, k1, k4, k5, k8, h1, c1, t0, e0, dt, t, ta, dh, dc; float k, k0, k6, k9, p, p0, p1, dp, h; int a=0; Label prompt1, prompt2; TextField input1, input2; CheckboxGroup source; Checkbox sourceUnlimited, sourceRenewable; Image oscillat, preypred; Panel panel; Button drawbutton; public void init() { prompt1 = new Label("E,J Energy source:"); input1 = new TextField("10000",6); prompt2 = new Label("K6 Depreciation factor of H:"); input2 = new TextField("5",6); source = new CheckboxGroup(); sourceUnlimited = new Checkbox("Unlimited Source",source,true); sourceRenewable = new Checkbox("Renewable Source",source,false); drawbutton = new Button("Draw"); panel = new Panel(); panel.setLayout( new GridLayout(2,4,20,0)); panel.add(prompt1); panel.add(input1); panel.add(sourceUnlimited); panel.add(drawbutton); panel.add(prompt2); panel.add(input2); panel.add(sourceRenewable); add(panel); oscillat = getImage(getDocumentBase(),"Gif/oscillat.gif"); preypred = getImage(getDocumentBase(),"Gif/preypred.gif"); } public boolean action (Event e,Object o) { ej = (float)Integer.parseInt(input1.getText()); k6 = 0.01f*(float)Integer.parseInt(input2.getText()); if (e.target instanceof Checkbox) { if (sourceUnlimited.getState() == true) { a=0; input2.setEditable(false); input2.setBackground(Color.black); } else { a=1; input2.setEditable(true); input2.setBackground(Color.white); } } repaint(); return true; } public void paint ( Graphics g ) { c=(float)5; k1=(float)0.002; k4=(float)0.1; k5=(float)0.02; k8=(float)0.3;p=(float)0; h=(float)10; t0=(float)3.2; e0=(float)0.08; dt=(float)0.1; t=(float)0; ta=(float)0; k=(float)0.01; k0=(float)0.01; k9=(float)0.005; p0=(float)0.08; g.drawRect(0,60,320,180); /*---- Start Program Oscillat----*/ if (a==0) { g.drawImage(oscillat, 321, 55, 380, 180, this); ej=0.1f*ej; while (t*t0<320) { dh=k1*ej*h-k4*c*h; dc=k5*c*h-k8*c; c1=c+dc*dt; if (c1<5) c1=5; h1=h+dh*dt; if (h1<8) h1=8; g.setColor(Color.blue); g.drawLine((int)(t0*ta),(int)(240-c),(int)(t0*t),(int)(240-c1)); g.setColor(Color.red); g.drawLine((int)(t0*ta),(int)(240-h),(int)(t0*t),(int)(240-h1)); ta=t; h=h1; c=c1; t+=dt; } /*----End Program Oscillat----*/ } /*---- Start Program Preypred----*/ else { g.drawImage(preypred, 321, 55, 450, 180, this); while (t*t0<320) { dp=k0*ej-k9*p-k*p*h; dh=k1*p*h-k4*c*h-k6*h; dc=k5*c*h-k8*c; c1=c+dc*dt; if (c1<1) c1=1; h1=h+dh*dt; if (h1<1) h1=1; p1=p+dp*dt; if(p1<0.001) p1=0.001f; g.setColor(Color.blue); g.drawLine((int)(t0*ta),(int)(240-c),(int)(t0*t),(int)(240-c1)); g.setColor(Color.red); g.drawLine((int)(t0*ta),(int)(240-h),(int)(t0*t),(int)(240-h1)); g.setColor(Color.green); g.drawLine((int)(t0*ta),(int)(240-p*p0),(int)(t0*t),(int)(240-p1*p0)); ta=t; h=h1; c=c1; p=p1; t+=dt; } /*---End Program Preypred---*/ } } } // Stefan Kontur, August 28th 2000*/ // Manuel Basler, October 24th 2000*/ // Enrique Ortega. August 31st, 2001