Type the centralised button-state rule (a 3-state machine)
Type the centralised button-state rule (a 3-state machine)
Answer
private void updateButtons(State s) { runButton.setEnabled(s == State.STOPPED); suspendButton.setEnabled(s == State.RUNNING); resumeButton.setEnabled(s == State.SUSPENDED); }
One method maps each state to which buttons are usable, so the UI can never offer an illegal action (no Suspend while stopped, no Run while running).