0

I'm currently creating a GUI program that is basically a timer by using only threading. I am currently having a program with my if statements. Please help.

 @Override
public void run() {

    while (count2 != 0) {
        try {

            Thread.sleep(1000);
             if (b == 0 && a > 0) {
                b = 60;
                a -= 1;
            }
            if (b > 59) {
                a += 1;
                b = 0;
            }
            if (c < 61 && c > 0) {
                c -= 1;
            }

            if (c > 59) {
                b += 1;
                c = 60;
                c -= 1;
            }
            if (b > 0 && b < 60 && c == 0) {
                b -= 1;
                c = 60;
            }



            jLabel4.setText("" + c);
            jLabel5.setText("" + b);
            jLabel6.setText("" + a);
            count2--;

        } catch (InterruptedException ex) {
            Logger.getLogger(Timer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    JOptionPane.showMessageDialog(this, "Time's up");

}

A is hours B is minutes C is seconds

count2 = (a * 360) + (b * 60) + c;

Thank you :)

  • 1
    First of all, call your variables `hours`, `minutes` and `seconds` instead of `a`, `b` and `c`. Then think about your logic - you want to decrement `seconds` and then cope with the situation where `seconds` goes negative. – Neil Masson Jan 17 '16 at 13:52

1 Answers1

0
public static int[] splitToComponentTimes(BigDecimal biggy)
{
    long longVal = biggy.longValue();
    int hours = (int) longVal / 3600;
    int remainder = (int) longVal - hours * 3600;
    int mins = remainder / 60;
    remainder = remainder - mins * 60;
    int secs = remainder;

    int[] ints = {hours , mins , secs};
    return ints;
}

I think this could solve your issue. Simply put the seconds in the method then it will return hours, mins and seconds.

Original Post: Convert seconds value to hours minutes seconds?

Community
  • 1
  • 1