~/ learn/ comp-308/ cards/ Part 3 recap: the Swing control panel & a state machine
1 of 6

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).

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/53eec23c-d1e6-4c63-9b07-0db18c4b3042/flashcard utf-8 LF