Advertisement
LucasSousa

SpeedCubing Timer v2015.1

Jan 13th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.91 KB | None | 0 0
  1. //Link para download do Arquivo .jar:
  2. //https://www.mediafire.com/?fz3r0cw23wzaazu
  3.  
  4. //Classe Cronometragem:
  5.  
  6. package javaapplication1;
  7.  
  8. import javax.swing.JLabel;
  9.  
  10. public class Cronometragem extends Thread {
  11.  
  12.     private JLabel label;
  13.     boolean threadCronoON = false;
  14.     boolean threadCronoOFF = true;
  15.     int centésimo = 0;
  16.     int segundo = 0;
  17.     int minuto = 0;
  18.  
  19.     public Cronometragem(JLabel stringTempo) {
  20.         label = stringTempo;
  21.     }
  22.  
  23.     public void run() {
  24.  
  25.         try {
  26.             while(true) {
  27.                 Thread.sleep((long) 9,6737);
  28.  
  29.                 threadCronoON = true;
  30.                
  31.                 if (CRONO3.isContador()) {
  32.                     centésimo++;
  33.                     if (centésimo == 100) {
  34.                         centésimo = 0;
  35.                         segundo++;
  36.                     }
  37.                     if (segundo == 60) {
  38.                         segundo = 0;
  39.                         minuto += 1;
  40.                     }
  41.                     String timerMinuto = "";
  42.                     String timerSegundo = "";
  43.                     String timerCentésimo = "";
  44.                     if (minuto < 10) {
  45.                         timerMinuto = "0" + minuto;
  46.                     } else {
  47.                         timerMinuto = String.valueOf(minuto);
  48.                     }
  49.                     if (segundo < 10) {
  50.                         timerSegundo = "0" + segundo;
  51.                     } else {
  52.                         timerSegundo = String.valueOf(segundo);
  53.                     }
  54.                     if (centésimo < 10) {
  55.                         timerCentésimo = "0" + centésimo;
  56.                     } else {
  57.                         timerCentésimo = String.valueOf(centésimo);
  58.                     }
  59.                     label.setText(timerMinuto + ":" + timerSegundo + "." + timerCentésimo);
  60.                     label.revalidate();
  61.                 }
  62.             }
  63.         } catch (InterruptedException e) {
  64.            
  65.             stop();
  66.             threadCronoON = false;
  67.             System.out.println("Bugou" + "\tValor de threadCronoON: " + threadCronoON);
  68.         }
  69.     }
  70. }
  71.  
  72. //----------------------------------------------------------------------------------//
  73.  
  74. //Classe da inspeção:
  75.  
  76. package javaapplication1;
  77.  
  78. import java.awt.Color;
  79. import javax.swing.JLabel;
  80.  
  81. public class InspTime extends Thread {
  82.  
  83.     private JLabel labelInsp;
  84.     boolean inspeçãoAtivada = false;
  85.     boolean inspeçãoDesativada = false;
  86.     boolean ganhouDNF = false;
  87.     int segInsp = 15;
  88.  
  89.     public InspTime(JLabel stringInsp) {
  90.         labelInsp = stringInsp;
  91.     }
  92.  
  93.     public void run() {
  94.         for (;;) {
  95.             try {
  96.                 inspeçãoAtivada = true;
  97.  
  98.                 Thread.sleep(1000L);
  99.                 if (CRONO3.isContadorInsp()) {
  100.                     segInsp--;
  101.  
  102.                     labelInsp.setText(String.valueOf(this.segInsp));
  103.                     labelInsp.revalidate();
  104.                    
  105.                     if(segInsp <= 3){
  106.                        
  107.                         labelInsp.setForeground(Color.RED);
  108.                     }
  109.                    
  110.                     if (segInsp <= 0) {
  111.                         labelInsp.setForeground(Color.BLACK);
  112.                         labelInsp.setText("DNF");
  113.                         labelInsp.revalidate();
  114.                         ganhouDNF = true;
  115.                     }
  116.                 }
  117.             } catch (InterruptedException e) {
  118.             }
  119.         }
  120.     }
  121. }
  122.  
  123. //----------------------------------------------------------------------------------//
  124.  
  125. //Classe principal:
  126.  
  127. package javaapplication1;
  128.  
  129. import java.awt.*;
  130. import java.awt.event.*;
  131. import javax.swing.*;
  132.  
  133. public class CRONO3 extends JFrame {
  134.  
  135.     long minutoFinal;
  136.     long centésimos;
  137.  
  138.     static JLabel tempoCorrendo;
  139.  
  140.     static boolean contador = true;
  141.     static boolean contador2 = true;
  142.     static boolean contador3 = true;
  143.  
  144.     boolean prontoParaPause = false;
  145.     boolean botãoSemUtilidadePorEnquanto = false;
  146.  
  147.     JLabel label1;
  148.     JLabel label2;
  149.     JLabel label3;
  150.     JLabel label4;
  151.  
  152.     JButton botãoStart;
  153.     JButton botãoStop;
  154.     JButton botãoStart2;
  155.  
  156.     Scrambler3x3 scramble1 = new Scrambler3x3();
  157.  
  158.     public CRONO3() {
  159.  
  160.         setTitle("Timer");
  161.         setSize(800, 340);
  162.         setDefaultCloseOperation(3);
  163.         setLayout(new FlowLayout(1));
  164.         setResizable(false);
  165.  
  166.         label1 = new JLabel();
  167.         label1.setText("Scramble: " + String.valueOf(Scrambler3x3.embaralhar3x3()));
  168.         label1.setFont(new Font(null, 0, 20));
  169.         add(label1);
  170.  
  171.         tempoCorrendo = new JLabel();
  172.         tempoCorrendo.setText("00:00.00");
  173.         tempoCorrendo.setFont(new Font("Times New Roman", 1, 200));
  174.         add(tempoCorrendo);
  175.  
  176.         label3 = new JLabel("Media: 00:00.00");
  177.         label3.setFont(new Font(null, 1, 20));
  178.         add(label3);
  179.  
  180.         label4 = new JLabel();
  181.         add(label4);
  182.  
  183.         Cronometragem timing = new Cronometragem(tempoCorrendo);
  184.         InspTime inspeção = new InspTime(tempoCorrendo);
  185.         //LongMedia media = new LongMedia();
  186.  
  187.         botãoStart = new JButton("Start");
  188.         botãoStart.setVisible(false);
  189.         botãoStart.setForeground(Color.red);
  190.         botãoStart.setToolTipText("Press Space to start");
  191.         botãoStop = new JButton("Stop");
  192.         botãoStop.setForeground(Color.red);
  193.         botãoStop.setToolTipText("Press Space to stop");
  194.         botãoStop.setEnabled(false);
  195.         botãoStart2 = new JButton("Start Insp");
  196.  
  197.         botãoStart2.addActionListener(new ActionListener() {
  198.             public void actionPerformed(ActionEvent eventoDoBotão) {
  199.                 if (inspeção.inspeçãoAtivada == false) {
  200.                     inspeção.start();
  201.                     tempoCorrendo.setText("15");
  202.                     label1.setText("");
  203.                     label3.setText("");
  204.                     tempoCorrendo.setFont(new Font("Times New Roman", 1, 300));
  205.                     setSize(800, 400);
  206.                     botãoStart2.setVisible(false);
  207.                     botãoStart.setVisible(true);
  208.                 }
  209.  
  210.                 iniciarInspeção(eventoDoBotão);
  211.                 tempoCorrendo.setText("15");
  212.  
  213.                 botãoStart2.setVisible(false);
  214.                 botãoStart.setVisible(true);
  215.  
  216.                 label1.setText("");
  217.                 label3.setText("");
  218.                 tempoCorrendo.setFont(new Font("Times New Roman", 1, 300));
  219.                 setSize(800, 400);
  220.                 botãoStart2.setVisible(false);
  221.                 botãoStart.setVisible(true);
  222.  
  223.             }
  224.         });
  225.  
  226.         botãoStart.addActionListener(new ActionListener() {
  227.             public void actionPerformed(ActionEvent eventoDoBotão) {
  228.  
  229.                 if (timing.threadCronoON == false) {
  230.                     timing.start();
  231.                     //media.start();
  232.  
  233.                     botãoStart.setEnabled(false);
  234.                     botãoStop.setEnabled(true);
  235.                     pausarInspeção(eventoDoBotão);
  236.                     inspeção.segInsp = 15;
  237.                     tempoCorrendo.setText("15");
  238.                     tempoCorrendo.setFont(new Font("Times New Roman", 1, 200));
  239.                     setSize(800, 340);
  240.  
  241.                 }
  242.  
  243.                 if ((timing.centésimo > 0) || (timing.minuto > 0) || (timing.segundo > 0)) {
  244.                     timing.centésimo = 0;
  245.                     timing.minuto = 0;
  246.                     timing.segundo = 0;
  247.                     botãoStart.setEnabled(false);
  248.                     botãoStop.setEnabled(true);
  249.                     iniciarInspeção(eventoDoBotão);
  250.                     inspeção.segInsp = 15;
  251.                     tempoCorrendo.setText("15");
  252.                     tempoCorrendo.setFont(new Font("Times New Roman", 1, 200));
  253.                     setSize(800, 340);
  254.                 }
  255.  
  256.                 iniciarTimer(eventoDoBotão);
  257.                 iniciarLongMedia(eventoDoBotão);
  258.  
  259.                 pausarInspeção(eventoDoBotão);
  260.                 tempoCorrendo.setFont(new Font("Times New Roman", 1, 200));
  261.                 setSize(800, 340);
  262.             }
  263.         });
  264.  
  265.         botãoStop.addActionListener(new ActionListener() {
  266.             public void actionPerformed(ActionEvent eventoDoBotão) {
  267.                 pausarTimer(eventoDoBotão);
  268.                
  269.                 pausarLongMedia(eventoDoBotão);
  270.  
  271.                 label1.setText("Scramble: " + String.valueOf(Scrambler3x3.embaralhar3x3()));
  272.                
  273.                 if(timing.minuto < 10){
  274.                     label3.setText("Last Time: 0" + timing.minuto + ":" + timing.segundo + "." + timing.centésimo);
  275.                    
  276.                 }
  277.                 if(timing.segundo < 10){
  278.                     label3.setText("Last Time: 0" + timing.minuto + ":0" + timing.segundo + "." + timing.centésimo);
  279.                 }
  280.                 if(timing.centésimo < 10){
  281.                     label3.setText("Last Time: 0" + timing.minuto + ":0" + timing.segundo + ".0" + timing.centésimo);
  282.                 }
  283.                
  284.                 botãoStop.setEnabled(false);
  285.                 botãoStart.setEnabled(true);
  286.  
  287.                 pausarInspeção(eventoDoBotão);
  288.  
  289.                 botãoStart2.setVisible(true);
  290.                 botãoStart.setVisible(false);
  291.             }
  292.         });
  293.  
  294.         add(botãoStart2);
  295.         reagirSpace(botãoStart2);
  296.  
  297.         add(botãoStart);
  298.         reagirSpace(botãoStart);
  299.  
  300.         add(botãoStop);
  301.         reagirSpace(botãoStop);
  302.     }
  303.  
  304.     public static void reagirSpace(JButton botão) {
  305.         botão.registerKeyboardAction(botão.getActionForKeyStroke(KeyStroke.getKeyStroke(32, 0, false)), KeyStroke.getKeyStroke(32, 0, false), 2);
  306.  
  307.         botão.registerKeyboardAction(botão.getActionForKeyStroke(KeyStroke.getKeyStroke(32, 0, true)), KeyStroke.getKeyStroke(32, 0, true), 2);
  308.     }
  309.  
  310.     void pausarTimer(ActionEvent evt) {
  311.         contador = false;
  312.     }
  313.  
  314.     void pausarInspeção(ActionEvent evt) {
  315.         contador2 = false;
  316.     }
  317.  
  318.     void pausarLongMedia(ActionEvent evt) {
  319.         contador3 = false;
  320.     }
  321.  
  322.     public static boolean isContador() {
  323.         return contador;
  324.     }
  325.  
  326.     public static boolean isContadorInsp() {
  327.         return contador2;
  328.     }
  329.  
  330.     public static boolean isContadorLongMedia() {
  331.         return contador3;
  332.     }
  333.  
  334.     void iniciarTimer(ActionEvent evt) {
  335.         tempoCorrendo.revalidate();
  336.         contador = true;
  337.     }
  338.  
  339.     void iniciarInspeção(ActionEvent evt) {
  340.         tempoCorrendo.revalidate();
  341.         contador2 = true;
  342.     }
  343.  
  344.     void iniciarLongMedia(ActionEvent evt) {
  345.         contador3 = true;
  346.     }
  347.  
  348.     public static void main(String[] args) {
  349.         CRONO3 tela = new CRONO3();
  350.  
  351.         tela.setVisible(true);
  352.         tela.setLocationRelativeTo(null);
  353.     }
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement