import java.util.*; import java.io.*; import javax.swing.Timer; import java.awt.event.*; public class MyWorld implements ActionListener { private PrintStream out; private ArrayList elements; // array to hold everything in my world. private MyWorldView view; // NEW private Timer passingTime; // NEW private double t; // simulation time private double delta_t; // in seconds private double refreshPeriod; // in seconds public MyWorld(){ this(System.out); // delta_t= 0.1[ms] and refreshPeriod=200 [ms] } public MyWorld(PrintStream output){ out = output; t = 0; refreshPeriod = 0.06; // 60 [ms] delta_t = 0.00001; // 0.01 [ms] elements = new ArrayList(); view = null; passingTime = new Timer((int)(refreshPeriod*1000), this); } public void addElement(PhysicsElement e) { elements.add(e); view.repaintView(); } public void setView(MyWorldView view) { this.view = view; } public void setDelta_t(double delta) { delta_t = delta; } public void setRefreshPeriod (double rp) { refreshPeriod = rp; passingTime.setDelay((int)(refreshPeriod*1000)); // convert from [s] to [ms] } public void start() { if(passingTime.isRunning()) return; passingTime.start(); } public void stop(){ } public void actionPerformed (ActionEvent event) { // like simulate method of Assignment 1, double nextStop=t+refreshPeriod; // the arguments are attributes here. for (; t getPhysicsElements(){ return elements; } public PhysicsElement find(double x, double y) { for (PhysicsElement e: elements) if (e.contains(x,y)) return e; return null; } }