Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Link para download do Arquivo .jar:
- //https://www.mediafire.com/?fz3r0cw23wzaazu
- //Classe Cronometragem:
- package javaapplication1;
- import javax.swing.JLabel;
- public class Cronometragem extends Thread {
- private JLabel label;
- boolean threadCronoON = false;
- boolean threadCronoOFF = true;
- int centésimo = 0;
- int segundo = 0;
- int minuto = 0;
- public Cronometragem(JLabel stringTempo) {
- label = stringTempo;
- }
- public void run() {
- try {
- while(true) {
- Thread.sleep((long) 9,6737);
- threadCronoON = true;
- if (CRONO3.isContador()) {
- centésimo++;
- if (centésimo == 100) {
- centésimo = 0;
- segundo++;
- }
- if (segundo == 60) {
- segundo = 0;
- minuto += 1;
- }
- String timerMinuto = "";
- String timerSegundo = "";
- String timerCentésimo = "";
- if (minuto < 10) {
- timerMinuto = "0" + minuto;
- } else {
- timerMinuto = String.valueOf(minuto);
- }
- if (segundo < 10) {
- timerSegundo = "0" + segundo;
- } else {
- timerSegundo = String.valueOf(segundo);
- }
- if (centésimo < 10) {
- timerCentésimo = "0" + centésimo;
- } else {
- timerCentésimo = String.valueOf(centésimo);
- }
- label.setText(timerMinuto + ":" + timerSegundo + "." + timerCentésimo);
- label.revalidate();
- }
- }
- } catch (InterruptedException e) {
- stop();
- threadCronoON = false;
- System.out.println("Bugou" + "\tValor de threadCronoON: " + threadCronoON);
- }
- }
- }
- //----------------------------------------------------------------------------------//
- //Classe da inspeção:
- package javaapplication1;
- import java.awt.Color;
- import javax.swing.JLabel;
- public class InspTime extends Thread {
- private JLabel labelInsp;
- boolean inspeçãoAtivada = false;
- boolean inspeçãoDesativada = false;
- boolean ganhouDNF = false;
- int segInsp = 15;
- public InspTime(JLabel stringInsp) {
- labelInsp = stringInsp;
- }
- public void run() {
- for (;;) {
- try {
- inspeçãoAtivada = true;
- Thread.sleep(1000L);
- if (CRONO3.isContadorInsp()) {
- segInsp--;
- labelInsp.setText(String.valueOf(this.segInsp));
- labelInsp.revalidate();
- if(segInsp <= 3){
- labelInsp.setForeground(Color.RED);
- }
- if (segInsp <= 0) {
- labelInsp.setForeground(Color.BLACK);
- labelInsp.setText("DNF");
- labelInsp.revalidate();
- ganhouDNF = true;
- }
- }
- } catch (InterruptedException e) {
- }
- }
- }
- }
- //----------------------------------------------------------------------------------//
- //Classe principal:
- package javaapplication1;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class CRONO3 extends JFrame {
- long minutoFinal;
- long centésimos;
- static JLabel tempoCorrendo;
- static boolean contador = true;
- static boolean contador2 = true;
- static boolean contador3 = true;
- boolean prontoParaPause = false;
- boolean botãoSemUtilidadePorEnquanto = false;
- JLabel label1;
- JLabel label2;
- JLabel label3;
- JLabel label4;
- JButton botãoStart;
- JButton botãoStop;
- JButton botãoStart2;
- Scrambler3x3 scramble1 = new Scrambler3x3();
- public CRONO3() {
- setTitle("Timer");
- setSize(800, 340);
- setDefaultCloseOperation(3);
- setLayout(new FlowLayout(1));
- setResizable(false);
- label1 = new JLabel();
- label1.setText("Scramble: " + String.valueOf(Scrambler3x3.embaralhar3x3()));
- label1.setFont(new Font(null, 0, 20));
- add(label1);
- tempoCorrendo = new JLabel();
- tempoCorrendo.setText("00:00.00");
- tempoCorrendo.setFont(new Font("Times New Roman", 1, 200));
- add(tempoCorrendo);
- label3 = new JLabel("Media: 00:00.00");
- label3.setFont(new Font(null, 1, 20));
- add(label3);
- label4 = new JLabel();
- add(label4);
- Cronometragem timing = new Cronometragem(tempoCorrendo);
- InspTime inspeção = new InspTime(tempoCorrendo);
- //LongMedia media = new LongMedia();
- botãoStart = new JButton("Start");
- botãoStart.setVisible(false);
- botãoStart.setForeground(Color.red);
- botãoStart.setToolTipText("Press Space to start");
- botãoStop = new JButton("Stop");
- botãoStop.setForeground(Color.red);
- botãoStop.setToolTipText("Press Space to stop");
- botãoStop.setEnabled(false);
- botãoStart2 = new JButton("Start Insp");
- botãoStart2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent eventoDoBotão) {
- if (inspeção.inspeçãoAtivada == false) {
- inspeção.start();
- tempoCorrendo.setText("15");
- label1.setText("");
- label3.setText("");
- tempoCorrendo.setFont(new Font("Times New Roman", 1, 300));
- setSize(800, 400);
- botãoStart2.setVisible(false);
- botãoStart.setVisible(true);
- }
- iniciarInspeção(eventoDoBotão);
- tempoCorrendo.setText("15");
- botãoStart2.setVisible(false);
- botãoStart.setVisible(true);
- label1.setText("");
- label3.setText("");
- tempoCorrendo.setFont(new Font("Times New Roman", 1, 300));
- setSize(800, 400);
- botãoStart2.setVisible(false);
- botãoStart.setVisible(true);
- }
- });
- botãoStart.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent eventoDoBotão) {
- if (timing.threadCronoON == false) {
- timing.start();
- //media.start();
- botãoStart.setEnabled(false);
- botãoStop.setEnabled(true);
- pausarInspeção(eventoDoBotão);
- inspeção.segInsp = 15;
- tempoCorrendo.setText("15");
- tempoCorrendo.setFont(new Font("Times New Roman", 1, 200));
- setSize(800, 340);
- }
- if ((timing.centésimo > 0) || (timing.minuto > 0) || (timing.segundo > 0)) {
- timing.centésimo = 0;
- timing.minuto = 0;
- timing.segundo = 0;
- botãoStart.setEnabled(false);
- botãoStop.setEnabled(true);
- iniciarInspeção(eventoDoBotão);
- inspeção.segInsp = 15;
- tempoCorrendo.setText("15");
- tempoCorrendo.setFont(new Font("Times New Roman", 1, 200));
- setSize(800, 340);
- }
- iniciarTimer(eventoDoBotão);
- iniciarLongMedia(eventoDoBotão);
- pausarInspeção(eventoDoBotão);
- tempoCorrendo.setFont(new Font("Times New Roman", 1, 200));
- setSize(800, 340);
- }
- });
- botãoStop.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent eventoDoBotão) {
- pausarTimer(eventoDoBotão);
- pausarLongMedia(eventoDoBotão);
- label1.setText("Scramble: " + String.valueOf(Scrambler3x3.embaralhar3x3()));
- if(timing.minuto < 10){
- label3.setText("Last Time: 0" + timing.minuto + ":" + timing.segundo + "." + timing.centésimo);
- }
- if(timing.segundo < 10){
- label3.setText("Last Time: 0" + timing.minuto + ":0" + timing.segundo + "." + timing.centésimo);
- }
- if(timing.centésimo < 10){
- label3.setText("Last Time: 0" + timing.minuto + ":0" + timing.segundo + ".0" + timing.centésimo);
- }
- botãoStop.setEnabled(false);
- botãoStart.setEnabled(true);
- pausarInspeção(eventoDoBotão);
- botãoStart2.setVisible(true);
- botãoStart.setVisible(false);
- }
- });
- add(botãoStart2);
- reagirSpace(botãoStart2);
- add(botãoStart);
- reagirSpace(botãoStart);
- add(botãoStop);
- reagirSpace(botãoStop);
- }
- public static void reagirSpace(JButton botão) {
- botão.registerKeyboardAction(botão.getActionForKeyStroke(KeyStroke.getKeyStroke(32, 0, false)), KeyStroke.getKeyStroke(32, 0, false), 2);
- botão.registerKeyboardAction(botão.getActionForKeyStroke(KeyStroke.getKeyStroke(32, 0, true)), KeyStroke.getKeyStroke(32, 0, true), 2);
- }
- void pausarTimer(ActionEvent evt) {
- contador = false;
- }
- void pausarInspeção(ActionEvent evt) {
- contador2 = false;
- }
- void pausarLongMedia(ActionEvent evt) {
- contador3 = false;
- }
- public static boolean isContador() {
- return contador;
- }
- public static boolean isContadorInsp() {
- return contador2;
- }
- public static boolean isContadorLongMedia() {
- return contador3;
- }
- void iniciarTimer(ActionEvent evt) {
- tempoCorrendo.revalidate();
- contador = true;
- }
- void iniciarInspeção(ActionEvent evt) {
- tempoCorrendo.revalidate();
- contador2 = true;
- }
- void iniciarLongMedia(ActionEvent evt) {
- contador3 = true;
- }
- public static void main(String[] args) {
- CRONO3 tela = new CRONO3();
- tela.setVisible(true);
- tela.setLocationRelativeTo(null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement