Java Reference
In-Depth Information
49 frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
50 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
51 frame.setVisible( true );
52 }
53
54 private static final double INTEREST_RATE =
10 ;
55 private static final double INITIAL_BALANCE
= 1000 ;
56
57 private static final int FRAME_WIDTH = 400 ;
58 private static final int FRAME_HEIGHT = 100 ;
59 }
S ELF C HECK
17. How do you place the Ðbalance: . . .Ñ message to the left of the
"Add Interest" button?
18. Why was it not necessary to declare the button variable as final ?
C OMMON E RROR 9.4: Forgetting to Attach a Listener
If you run your program and find that your buttons seem to be dead, double-check
that you attached the button listener. The same holds for other user interface
components. It is a surprisingly C OMMON E RROR to program the listener class and
the event handler action without actually attaching the listener to the event source.
P RODUCTIVITY H INT 9.1: Don't Use a Container as a
Listener
In this topic, we use inner classes for event listeners. That approach works for
many different event types. Once you master the technique, you don't have to think
about it anymore. Many development environments automatically generate code
with inner classes, so it is a good idea to be familiar with them.
However, some programmers bypass the event listener classes and instead turn a
container (such as a panel or frame) into a listener. Here is a typical example. The
Search WWH ::




Custom Search