1 package model; 2 3 import java.util.function.Consumer; 4 5 class Button extends MenuItem { 6 7 Consumer<Button> action; 8 String menuText; 9 int id; 10 boolean enabled = true; 11 12 13 Button(int id, String text, Consumer<Button> action) { 14 this.id = id; 15 this.menuText = text; 16 this.action = action; 17 } 18 19 void render() { 20 System.out.println(id + ". " + menuText); 21 } 22 23 void setAction(Consumer<Button> action) { 24 this.action = action; 25 } 26 27 void press() { 28 if (enabled && action != null) { 29 action.accept(this); 30 } 31 } 32 33 boolean match(int id) { 34 return this.id == id; 35 } 36 37 boolean isEnabled() { 38 return enabled; 39 } 40 41 void enable() { 42 enabled = true; 43 } 44 void disable() { 45 enabled = false; 46 } 47 } 48