~/ 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/c5443c0e-86a0-4770-be59-9b4094ca2d42/flashcard utf-8 LF