[prog] Seeking and appropriate Java component

Sue Stones suzo at spin.net.au
Thu May 6 19:11:05 EST 2004


I am writting a program in Java (for a concurrent Programming assignment). It 
is a graphical application that simulates the movement of some "particles" ie 
brownian motion type of thing.  Each particle is run as a separate thread, 
and it is posible to remove particles and create new ones.

I want to be able to state somewhere, how many particles there are.  I have 
put in a panel and tried to use a label, but there are 2 problems.  (i) the 
label is created before the threads (ii) I don't know how to update a label.

Does anyone know of any Java components that are like a lable but which can be 
updated?

Searching hasn't produced a list of possible componenets, so I don't quite 
know where to look.

Another problem with the program, is that all the particles drift to the north 
west.  I am using "Random" to produce the movements, but clearly "Random is 
biased.  Any one know the solution to this?  Here are the calls to Random.

  protected final Random rng = new Random();

  public synchronized void move() {
    x += rng.nextInt(10) - 5;
    y += rng.nextInt(20) - 10;
  } // move

sue


More information about the Programming mailing list