Answers to Self-Review Exercises

22.1
  1. JMenu.

  2. addSeparator.

  3. stateChanged, ChangeListener.

  4. anchor.

22.2
  1. False. A JFrame does not require any menus.

  2. False. The variable fill belongs to the GridBagConstraints class.

  3. True.

  4. True.

22.3
  1. JMenubar should be JMenuBar.

  2. The first argument to the constructor should be either SwingConstants.HORIZONTAL or SwingConstants.VERTICAL, and the keyword new must be used after the = operator.

  3. The constant should be either BOTH, HORIZONTAL, VERTICAL or NONE.

  4. paintcomponent should be paintComponent, and the method should call super.paint-Component( g ) as its first statement.

  5. The JFrame’s setSize method must also be called to establish the size of the window.

Get Java™ How to Program, Seventh Edition 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.