import java.awt.*; import java.applet.Applet; // This program copyright Michael Ringel, 1999. public class Woburn2 extends Applet { //open 1 Woburn private boolean laidOut = false; private boolean havegone = false; TextField tf; Button b; int density, iter, x, y,x1,x2,x3,x4,y1,y2,y3,y4; double distance,d1,d2,d3,d4,da,db; public void init() {//open 2 init setLayout(null); tf = new TextField(10); tf.enable(); tf.setText("1000"); b = new Button("Run"); add(b); add(tf); validate(); }//close 2 init public boolean action (Event e, Object arg) {//open 2 action if (e.target==b) {//open 3 button density = Integer.parseInt(tf.getText()); if (density>100000) { density=(int)100000; tf.setText("100000"); } if (density<0) { density=(int)0; tf.setText("0"); } havegone=true; repaint(); return true; }//close 3 button return false; }//close 2 action public void paint (Graphics g) {//open 2 paint if (!laidOut) {//open 3 layout tf.reshape(10,10,60,30); b.reshape(75,10,60,30); laidOut = true; }//close 3 layout g.setColor(getBackground()); g.draw3DRect(11,46,400,400,false); g.draw3DRect(10,45,402,402,true); //g.setColor(getForeground()); if (havegone==true) {//open 3 if loop x1=(int)(Math.random()*398)+12; y1=(int)(Math.random()*398)+47; x2=(int)(Math.random()*398)+12; y2=(int)(Math.random()*398)+47; x3=(int)(Math.random()*398)+12; y3=(int)(Math.random()*398)+47; x4=(int)(Math.random()*398)+12; y4=(int)(Math.random()*398)+47; for (iter=0;iter<100;iter++) {//open extra iter loop for non-ag indivs x=(int)(Math.random()*398)+12; y=(int)(Math.random()*398)+47; g.setColor(getForeground()); g.fillOval(x,y,4,4); }//close extra iter loop for (iter=0;iter60.0) {//open 5 while loop x=(int)(Math.random()*398)+12; y=(int)(Math.random()*398)+47; d1=Math.sqrt((double)(((x-x1)*(x-x1))+((y-y1)*(y-y1)))); d2=Math.sqrt((double)(((x-x2)*(x-x2))+((y-y2)*(y-y2)))); d3=Math.sqrt((double)(((x-x3)*(x-x3))+((y-y3)*(y-y3)))); d4=Math.sqrt((double)(((x-x4)*(x-x4))+((y-y4)*(y-y4)))); da=Math.min(d1,d2); db=Math.min(da,d3); distance=Math.min(db,d4); };//close 5 while loop g.setColor(getForeground()); g.fillOval(x,y,4,4); }//close 4 iter loop }//close 3 if loop g.setColor(getBackground()); g.draw3DRect(11,46,400,400,false); g.draw3DRect(10,45,402,402,true); }//close 2 paint }//close 1 Woburn