Small thread exercise in Java
The random numbers were supposed to be printed on the console, but I decided to use 2 JTextFields to show the numbers
Exercise: "Write an application that has a window with a JButton ("Stop"). When the application starts, it should create and start two different threads: Thread A should generate random numbers between 1000 and 9999 in a loop until it is interrupted. Each time a new random number has been generated, it should be output to the console. The loop should contain no sleeps! Thread B should generate random numbers between 1 and 9 in a loop until it is interrupted. Each time a new random number has been generated, the number should be output to the console. Between each new number generated, Thread B should sleep for 0.5 seconds.
Both Thread A and Thread B should keep track of how many numbers they have generated. When the "Stop" button is pressed, both threads should end. When they have ended, your application should print the number of random numbers generated by Thread A and Thread B, respectively (you can use a System.out.println("")). Notice that it is IMPORTANT to ensure that both Thread A and Thread B have really ended before printing out the number of random numbers generated by each of them."