import java.awt.*; import java.applet.*; import java.awt.event.*; public class Space extends Applet implements Runnable { static final double dt=0.05; Cluster cluster; boolean running; Image image; public void init() { setBackground(Color.white); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { start(); } }); } public synchronized void start() { cluster=new Cluster(); if (!running) { running=true; new Thread(this,"Physics").start(); } } public void stop() { running=false; } public void run() { while (running) { for (int i=0;i<10;i++) synchronized (this) { cluster.step(0,dt/10); } repaint(); try { Thread.sleep((long)(dt*1000)); } catch (InterruptedException e) { e.printStackTrace(); } } } public void update(Graphics g) { paint(g); } public synchronized void paint (Graphics g) { int width=getSize().width,height=getSize().height; if (image==null) image=createImage(width,height); Graphics og=image.getGraphics(); og.clearRect(0,0,width,height); og.translate(width/2,height/2); for (int i=0;i