Command (Chapter 24)

SOLUTION 24.1Java Swing applications commonly apply the MEDIATOR pattern, registering a single object to receive all GUI events. This object mediates the interaction of the components and translates user input into commands for business domain objects.
SOLUTION 24.2Your code should look something like:
 protected JMenu fileMenu() { if (fileMenu == null) { fileMenu = new JMenu("File"); Font f = SwingFacade.getStandardFont(); fileMenu.setFont(f); JMenuItem save = new JMenuItem("Save"); save.setFont(f); fileMenu.add(save); save.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { save(); } } ); JMenuItem load = new JMenuItem("Load"); load.setFont(f); fileMenu.add(load); load.addActionListener ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.