/* UI Library */ class Rect { public int x, y; public int w, h; public Rect(int ax, int ay, int aw, int ah){ x = ax.clone; y = ay.clone; w = aw.clone; h = ah.clone; } public int cx(){ return x + w / 2; } public int cy(){ return y + h / 2; } public boolean contains(Point p){ return (x <= p.x) && (p.x < x + w) && (y <= p.y) && (p.y < y + h); } } interface Control { public void paint(Display display); public boolean handleEvent(Event event); } class Display extends Panel { public Display(Point size) { Panel(); frame_ = new Frame("Book Checkout"); frame_.add("Center", this); frame_.resize(size.x + 20, size.y + 40); frame_.setVisible(true); controls_ = new List(); } public void invalidate(){ clear(); for(Control control: controls_){ control.paint(this); } repaint(); } public boolean handleEvent(Event event){ boolean handled = false; for(Control control: controls_){ if(control.handleEvent(event)){ handled = true; } } if(handled){ invalidate(); } return handled; } public void add(Control control) { controls_.add(control); } public void remove(Control control) { controls_.remove(control); } private Frame frame_; private List controls_; } class Buttons implements Control { public Buttons() { list_ = new List