How do I update a panel every decrement of hours, minutes and seconds. The given code works fine with CMD-based display but not with panels.
if((!_hour.equals(""))&&(!_minute.equals(""))&&(!_second.equals("")))
{
frame.dispose();
//Timer time = new Timer(1000, new TimerListener());
hour = Integer.parseInt(hours.getText());
minute = Integer.parseInt(minutes.getText());
second = Integer.parseInt(seconds.getText());
hour = ((hour>=0 && hour<24) ? hour : 0);
minute = ((minute>=0 && minute<60) ? minute : 0);
second = ((second>=0 && second<60) ? second : 0);
while(second > 0)
{
try
{
Thread.sleep(1000);
second--;
timeleft.setText("Time left: " +obj.setTime(hour, minute, second));
if(second == 0)
{
while(minute > 0)
{
try
{
Thread.sleep(60000);
minute--;
timeleft.setText("Time left: " +obj.setTime(hour, minute, second));
if(minute == 0)
{
while(hour > 0)
{
try
{
Thread.sleep(3600000);
hour--;
timeleft.setText("Time left: " +obj.setTime(hour, minute, second));
}
catch(InterruptedException err)
{
err.printStackTrace();
}
}
}
}
catch(InterruptedException err)
{
err.printStackTrace();
}
}
}
paneltimer.add(timeleft);
timer.add(paneltimer);
timer.setUndecorated(true);
timer.setVisible(true);
timer.pack();
timer.setAlwaysOnTop (true);
timer.setLocation(500, 0);
}
catch(InterruptedException err)
{
err.printStackTrace();
}
}
}
It should display something like this(but seconds should be, for example 3 if I have inputted 3 but in my case it would output 2 initially) and the panel should update every time the seconds, minutes and hours are being decremented however it just stays as displayed below:
Alongside that, it gives the following exception.
Please tell me how to update a panel based on my implementation thanks!