JButton

JFrame, JPanel, and JButton work exactly like their AWT counterparts, except for a wrinkle that has been added to JFrame. JFrame is really a compound object. It has a single child of type JRootPane, and that child manages four other components: See [Topley, p79] for a discussion of this new architecture. All code that used to look like frame.add( ... ), will now look like frame.getContentPane().add( ... ).

The next feature to comment on is "anonymous inner class". Instead of declaring an inner class with one Java statement, and then instantiating and using it in another statement, an anonymous class combines the two steps in a single Java expression. An anonymous class is defined by a Java expression, not a Java statement. This means that an anonymous class definition can be included within a larger Java expression such as an assignment or method call. [Flanagan97a, p103, p117]

The ActionListener object is an example. Instead of writing code like:

   class ButtonListener implements ActionListener {
      public void actionPerformed( ... ) {
         ...
      }
   }
   ActionListener bl = new ButtonListener();
Everything is condensed into:
   ActionListener bl = new ActionListener() {
      public void actionPerformed( ... ) {
         ...
      }
   };
The WindowAdapter object is even more condensed. Inside the addWindowListener() method invocation, the anonymous inner class expression is embedded. That is why there is an "apparently" extra ");" at the end.

In the first case, we "inline" defined a class and declared an instance of that class. In the second case, we "inline" defined a class, declared an instance of that class, and, passed the instance as an argument to a method invocation.