Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
DealerTimer - DealerTimer.java

DealerTimer.java

Caricato da:
Scarica il programma completo

  1. package dealertimer;
  2.  
  3. public class DealerTimer implements Runnable {
  4.  
  5.     private static final String[] LEVELS;
  6.  
  7.     static {
  8.         LEVELS = new String[29];
  9.         LEVELS[0] = "25/50";
  10.         LEVELS[1] = "50/100";
  11.         LEVELS[2] = "100/200";
  12.         LEVELS[3] = "150/300";
  13.         LEVELS[4] = "200/400";
  14.         LEVELS[5] = "300/600";
  15.         LEVELS[6] = "400/800";
  16.         LEVELS[7] = "500/1000";
  17.         LEVELS[8] = "600/1200";
  18.         LEVELS[9] = "800/1600";
  19.         LEVELS[10] = "1000/2000";
  20.         LEVELS[11] = "1500/3000";
  21.         LEVELS[12] = "2000/4000";
  22.         LEVELS[13] = "3000/6000";
  23.         LEVELS[14] = "4000/8000";
  24.         LEVELS[15] = "6000/12K";
  25.         LEVELS[16] = "8000/16K";
  26.         LEVELS[17] = "10K/20K";
  27.         LEVELS[18] = "15K/30K";
  28.         LEVELS[19] = "20K/40K";
  29.         LEVELS[20] = "30K/60K";
  30.         LEVELS[21] = "40K/80K";
  31.         LEVELS[22] = "50K/100K";
  32.         LEVELS[23] = "60K/120K";
  33.         LEVELS[24] = "80K/160K";
  34.         LEVELS[25] = "100K/200K";
  35.         LEVELS[26] = "150K/300K";
  36.         LEVELS[27] = "200K/400K";
  37.         LEVELS[28] = "300K/600K";
  38.     }
  39.     private int level;
  40.     private int second;
  41.     private int seconds;
  42.     private boolean pause;
  43.     private boolean stop;
  44.     private Thread start;
  45.  
  46.     public DealerTimer() {
  47.         this.seconds = 0;
  48.         this.pause = true;
  49.         this.stop = true;
  50.         this.level = 0;
  51.     }
  52.  
  53.     public void addMinute() {
  54.         this.second += 60;
  55.         this.seconds += 60;
  56.  
  57.     }
  58.  
  59.     public int getMinutes() {
  60.         return this.second / 60;
  61.     }
  62.  
  63.     public int getSeconds() {
  64.         return this.second - 60 * (this.getMinutes());
  65.     }
  66.  
  67.     public String getLevel() {
  68.         return DealerTimer.LEVELS[this.level];
  69.     }
  70.  
  71.     public void run() {
  72.         while (!this.stop) {
  73.             try {
  74.                 Thread.sleep(1000);
  75.                 if (this.second <= 0 && this.seconds != 0) {
  76.                     this.second = this.seconds;
  77.                     if(this.level+1<DealerTimer.LEVELS.length){
  78.                         this.level++;
  79.                     }
  80.                 } else if (!this.pause && !this.stop && this.seconds != 0) {
  81.                     this.second--;
  82.                 }
  83.             } catch (InterruptedException ex) {
  84.                 ex.printStackTrace();
  85.             }
  86.         }
  87.     }
  88.  
  89.     public void start() {
  90.         if (this.stop) {
  91.             this.start = new Thread(this);
  92.             this.pause = false;
  93.             this.stop = false;
  94.             this.start.start();
  95.         } else {
  96.             this.stop();
  97.         }
  98.     }
  99.  
  100.     public void pause() {
  101.         this.pause = !this.pause;
  102.  
  103.     }
  104.  
  105.     public void reset() {
  106.         this.seconds = 0;
  107.         this.second = 0;
  108.     }
  109.  
  110.     public boolean getStop() {
  111.         return this.stop;
  112.     }
  113.  
  114.     public boolean getPause() {
  115.         return this.pause;
  116.     }
  117.  
  118.     private void stop() {
  119.         this.stop = true;
  120.         this.second = this.seconds;
  121.         this.level = 0;
  122.     }
  123.  
  124.     public boolean isEndeed() {
  125.         if (this.second == 0 && !this.stop && !this.pause && this.seconds != 0) {
  126.             return true;
  127.         }
  128.         return false;
  129.     }
  130. }