Java Reference
In-Depth Information
Most of the code in this constructor should be familiar to you. However, notice one
thing: an action listener is added only to the push button jbtnCompare . Action
listeners are not added to the text fields. Here's why: the contents of the text fields
are needed only when the Compare button is pushed. At no other time are their con-
tents required. Thus, there is no reason to respond to any text field events. As you be-
gin to write more Swing programs, you will find that this is often the case when us-
ing a text field.
4. Begin creating the actionPerformed( ) event handler, as shown next. This method is
called when the Compare button is pressed.
The method begins by confirming that the user has entered a file name into each of
the text fields. If this is not the case, the missing file name is reported and the handler
returns.
5. Now, finish actionPerformed( ) by adding the code that actually opens the files and
then compares them.
Search WWH ::




Custom Search