I am making a program that shows cellular growth through an array. I have gotten it so when I press the start button, the array updates every 10 seconds in a while(true){} l
I would suggest using a seperate thread to handle the array. Make sure you are using thread safe object (check Java Docs) and simply call .start() on your thread object when you want to start. Keep a pointer to it so you can pause it via setPaused(true)
Something like this....
class MyArrayUpdater extends Thread {
private volatile boolean enabled = true;
private volatile boolean paused = true;
@Override
public void run() {
super.run();
try {
while (enabled) {
if (!paused) {
// Do stuff to your array here.....
}
Thread.sleep(1);
}
} catch (InterruptedException ex) {
// handle ex
}
}
public void setEnabled(boolean arg) {
enabled = arg;
}
public void setPaused(boolean arg) {
paused = arg;
}
}