/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package eric.monkey; import java.util.ArrayList; import java.util.Enumeration; import java.util.logging.Level; import java.util.logging.Logger; import rene.zirkel.ZirkelCanvas; import rene.zirkel.objects.ConstructionObject; import rene.zirkel.objects.PointObject; /** * * @author erichake */ public class monkey { private ZirkelCanvas ZC; private long waitTime=5; private ArrayList mobiles=new ArrayList(); private ArrayList mobilesCoords=new ArrayList(); private boolean inprogress=false; private static Thread shakeThread=null; public monkey(ZirkelCanvas zc) { ZC=zc; initMobiles(); } public void initMobiles() { mobiles.clear(); mobilesCoords.clear(); Enumeration e=ZC.getConstruction().elements(); while (e.hasMoreElements()) { final ConstructionObject c=(ConstructionObject) e.nextElement(); if (c instanceof PointObject) { PointObject pt=(PointObject) c; if (pt.moveable()&&pt.insidewindow()) { mobiles.add(pt); double[] tab={pt.getX(), pt.getY()}; mobilesCoords.add(tab); } } } } public void reset() { for (int k=25; k>0; k--) { long t0=System.currentTimeMillis(); for (int i=0; i0) { Thread.sleep(time); } } catch (Exception ex) { } } } public void move1step() { for (int i=0; i0) { Thread.sleep(time); } } catch (Exception ex) { } } reset(); shakeThread=null; } }; shakeThread.setPriority(Thread.MIN_PRIORITY); shakeThread.start(); } public void stop() { inprogress=false; } }