0

I'm working on a sudoku solver in javafx and I need to show the algorithm solving. My board is a bunch of buttons laid out in a 9x9 grid and the user enters the puzzle and I solve it.

The solving works fine but I cannot get the algorithm to run. This is what I have but whenever I run the program the window stops responding and I have to terminate the window and get an interrupted by signal 2: SIGINT.

private void loop(Sequence s) {

    long currentTime = System.currentTimeMillis();

    long lastTime = System.currentTimeMillis();

    int x = s.getX();

    int y = s.getY();

    String n = Integer.toString(s.getNum());

    Button button = buttons.get(x).get(y);

    boolean isFinished = true;

    while(isFinished) {

        if(currentTime > lastTime + 400){

            button.setText(n);
            isFinished = false;

        } else {
               currentTime = System.currentTimeMillis();
          }
    }


 public void show(){

   for (Sequence s : sequences){
       loop(s);
    }

}
Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
abbyJeffers
  • 1
  • 1
  • 1
  • 3
    It looks to me like you might have an infinite loop. From what I can tell that while loop is just meant to wait about half a second, but I imagine it could be cycling millions of times before that condition is met in the if statement. If you are trying to pause your code for a short time check out this thread: https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java. – tshimkus Feb 09 '19 at 04:11
  • Don't run the loop in the same thread with UI. Run it as a separate task. – Ken Bekov Feb 09 '19 at 10:27

0 Answers0