View Single Post
  #1 (permalink)  
Old 11-09-2007, 10:25 AM
ixhabbaba ixhabbaba is offline
Member
 
Join Date: Nov 2007
Posts: 1
ixhabbaba is on a distinguished road
Simulating Brownian Motion
Hi! I'm making an applet to simulate Brownian motion, which works just fine.
However, I have this problem with adding an extra feature. The main class
looks like this:

Code:
public class BrownAnimation extends Applet implements MouseListener{ boolean clicked=false; int xborder=400; int yborder=400; int x; int y; Model m; View v; Simulation sim; Manipulation manic; public void init(){ addMouseListener(this); /* m=new Model(200,200,xborder,yborder); v=new View(m); sim=new Simulation(m,v); manic=new Manipulation(m); add(v); add(manic); */ } public void mouseClicked(MouseEvent e) { if(clicked==false) { x=e.getX(); y=e.getY(); m=new Model(x,y,xborder,yborder); v=new View(m); sim=new Simulation(m,v); manic=new Manipulation(m); add(v); add(manic); clicked=true; } } }
Model keeps track of individual particles, and makes them move.
View draws up the graphical components.
Manipulation is a set of buttons to manipulate particle velocity.
Simulation clocks it all.

The Model constructor takes four parameters: the coordinates for the particle
"ground zero", and the limits of the "beaker". If a particle hits the beaker wall,
it will stop.

This all works just fine using the code segment I've commented away.
However, I tried to add an extra feature with the mouseListenet:
The ability to choose a "ground zero" by clicking. Now, the applet
displays nothing, although it loads, and reacts to clicking
(I let it print out a line to the terminal when clicked).

Could you please help me solve this problem?
This is a school project, and they're not helping me.....


PS: The forum screws up my indentation for some reason. Sorry about that.

Last edited by JavaBean : 11-09-2007 at 11:26 AM. Reason: Code placed inside [code] block.
Reply With Quote
Sponsored Links