I am creating a program that is creating gates(AND, OR etc.), but when I want to create an SR latch, I need to use a timer.
So when this method(inputChanged) is called it should check if the timer is running. If it is running it should do nothing. (This is were I am stuck...)
Otherwise it should check if the new value deviates from the old value(getOutputValue()
).
If it does it should save the new value and send an interrupt signal after a small delay. I am using setInitialDelay() for the initial delay but I don't know how to send an interrupt signal.
I wonder what I've done wrong in this code, because it is not working too well....
public void inputChanged()
{
timer = new javax.swing.Timer(delay, new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
// Check if timer is running.
if(timer.isRunning())
{
boolean value = calculateValue();
// new Value old Value
if(calculateValue() != getOutputValue())
{
timer.setInitialDelay(delay);
timer.stop();
}
outputChanged(value);
}
}
});
timer.start();
}