I want to take the difference between the changed value and the curent date of the spinnerdatemodel as the delay for the timer. This is the JSpinner
:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, 5);
Date max = cal.getTime();
SpinnerDateModel sdm = new SpinnerDateModel(cal.getTime(),null, max,Calendar.HOUR_OF_DAY);
jSpinner1 = new javax.swing.JSpinner(sdm);
jSpinner1 .setEditor(new JSpinner.DateEditor(jSpinner1 , "hh:mm:ss"));
This is the code that I tried but is not working:
jSpinner1.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
JSpinner jSpinner = (JSpinner)e.getSource();
Date time = (Date) jSpinner.getValue();
if(jCheckBox1.isSelected())
{
delay = 1000 * (int) time.getTime();
}
}
});
timer = new Timer(delay, new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
f.getContentPane().setBackground(c);
}
});
All I want is to change the color of a frame background in a specific determined time. Any help will be extremely apreciated.
EDIT:
I click the "on time" checkbox and I change the value from the SpinnerDateModel
. After all this, when I press start the timer will fire with the delay from the SpinnerDateModel
executing the task of changing a frame`s color.
My code just changes the color imediatly I press start, wtihout the delay.