The idea is to create a program that will race horses across a window in Java. The program will be an application that will instantiate multiple instances of Horse threads. The application will run in a window that will contain three buttons:
A total of 6 horses will run the race.
When the application starts, the horses will be lined up at the starting line. When the user clicks the [run race] button, the horses run. Your program will animate their running across the window, ultimately declaring a winner. Notice there is literally a race condition in this program: You must ensure that the horse that crosses the finish line first detects that it has won, declares itself the winner, and ensures that the other horses do not declare themselves winners, all as an atomic operation. Your program will need a lock for the critical section of code. It might have a shared memory condition variable (keepRunning or some such) that tells the other horses when to stop running. You might use the interrupted exception to stop the horses from running if you wish. You may use whichever method seems the most direct to you. Certainly, you will not use the thread.stop() method in the Java program to stop the other horses from running (for reasons to be described in class).
When a horse crosses the finish line, you will declare a winner via a dialog box. The dialog box will also report the winning time. You will use a timer as was demonstrated in the selection and merge sort programs. The timer returns milliseconds which you will convert into seconds and report in the dialog box.
The user will click the dialog to close it. If the user then presses the [reset] button the horses should be redrawn back at the starting line. If the user clicks the [quit] button, the program should terminate. All the buttons should work properly. Some interface design in alerting the user how to use the interface will be needed. Be sure your program does not generate runtime errors if the buttons are clicked in an incorrect pattern.