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 Timer passingTime; // NEW private double t; // simulation time private double delta_t; // in seconds private double refreshPeriod; // in seconds private MyWorldView view; public MyWorld(){ this(System.out); } public MyWorld(PrintStream output){ out = output; t = 0; refreshPeriod = 0.05; // [s] delta_t = 0.005; // [s] elements = new ArrayList(); view = new MyWorldView(this); passingTime = new Timer((int)(refreshPeriod*1000), this); } public void addElement(PhysicsElement e) { elements.add(e); view.repaint(); } public PhysicsElement getCollidingElement(Ball b) { PhysicsElement pe; for (PhysicsElement e: elements){ pe = e.collide(b); if (pe!=null) return pe; } return null; } public MyWorldView getView() { return view; } public ArrayList getPhysicsElements(){ return elements; } public void start() { if(passingTime.isRunning()) return; passingTime.start(); } public void actionPerformed (ActionEvent event) { // like simulate method of 1st. Assignment, double nextStop=t+refreshPeriod; // the arguments are attributes here. for (; t