Advertisement
heavenriver

Application.java (judge version)

Apr 15th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package runners_judge;
  2.  
  3. import javax.swing.*;
  4.  
  5. public class Application
  6.  
  7.     {
  8.     public static void main(String[] args)
  9.         {
  10.         Start s = null;
  11.         Judge j = new Judge();
  12.         int runners = 0;
  13.         while(runners <= 0)
  14.             {
  15.             try
  16.                 {
  17.                 runners = Integer.parseInt(JOptionPane.showInputDialog(null, "Insert number of runners:"));
  18.                 if(runners >= 0)
  19.                     s = new Start(runners);
  20.                 }
  21.             catch(NumberFormatException e)
  22.                 {
  23.                 JOptionPane.showMessageDialog(null, "Error: invalid number format");
  24.                 }
  25.             }
  26.         Thread t = new Thread(j);
  27.         t.setDaemon(true);
  28.         t.start();
  29.         Thread[] threads = new Thread[runners];
  30.         for(int i = 0; i < runners; i++)
  31.             {
  32.             Runner r = new Runner(i, s);
  33.             threads[i] = new Thread(r);
  34.             threads[i].start();
  35.             }
  36.         for(int i = 0; i < runners; i++)
  37.             {
  38.             try
  39.                 {
  40.                 threads[i].join();
  41.                 }
  42.             catch(InterruptedException e)
  43.                 {
  44.                 e.printStackTrace();
  45.                 }
  46.             }
  47.         Judge.printChart();
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement