Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, I'm very new to java and I've been dealing with this issue for more then 10 days. I have an app to create with two options, on time and count down, where user chooses desired option, and on time set new window opens and it blinks changing colors. Option two works just fine, but option number on will not start at time defined.

This is code for first option:


if (jCheckBox1.isSelected()){
        st = true;
   
    set = jFormatted.getText();
    try{
     
     String myDateString = jFormatted.getText();
     SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
       Date date = sdf.parse(myDateString);
        date.toString();
       Calendar c = Calendar.getInstance();
            c.setTimeInMillis(razlika);
    }
       
    catch(Exception e){}
   
       sw = new SwingWorker() {  
            @Override
            protected Object doInBackground() throws Exception{
                Thread.sleep(razlika);
              
              Calendar c = Calendar.getInstance();
            c.setTimeInMillis(razlika);
           
              Thread.sleep(c.getTimeInMillis(),s.getTime1());
                FrameBoja.Pocetak();
                while(st){
                  Thread.sleep(s.getTime1()); 
                    FrameBoja.cf.getContentPane().setBackground(s.getColor());
                    Thread.sleep(s.getSpeed());
                     FrameBoja.cf.getContentPane().setBackground(new Color (44,62,80)); 
                      Thread.sleep(s.getSpeed());  
                     
                }
                return null;
            }
        }; 

and here it is for second one

else if(jCheckBox2.isSelected()){
        s.setTime2((Integer)jSpinner2.getValue()*1000);
        st = true;
        sw = new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                Thread.sleep(s.getTime2());
                 FrameBoja.Pocetak();
                 while(st){
                     FrameBoja.cf.getContentPane().setBackground(s.getColor());  
                     Thread.sleep(s.getSpeed());
                     FrameBoja.cf.getContentPane().setBackground(new Color (44,62,80));
                     Thread.sleep(s.getSpeed());  
                 }
                 return null;
            }
        };
        sw.execute();


        sw.execute();


Any help, advice is more then welcome.

What I have tried:

I have tried a lots of things, changed time formatters, changed variables...
Posted
Updated 14-Jul-19 21:19pm

1 solution

Could be something in the area with all that messing about with strings and times has thrown an exception. But since you ignore any exceptions that you catch there is no way of knowing. Use the debugger to step through the code and see what is happening. You are also using the same text input for different items, and different calendars with the same variable name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900