Java Reference
In-Depth Information
public static void listen(Frame f)
{
f.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
You may have found that refactoring FlightPanel_1 made the application disappear, with
no main() method appearing anywhere. It often happens that refactoring a monolithic
application produces a facade and eliminates the presence of a main() method on any of the
new classes. To achieve the results of the original application in this example, you can create
a standalone class with just one method:
package com.oozinoz.applications;
import java.awt.Dimension;
import javax.swing.*;
import com.oozinoz.ui.SwingFacade;
public class ShowFlightPanel
{
public static void main(String[] args)
{
FlightPanel fp = new FlightPanel();
fp.setPreferredSize(new Dimension(300, 200));
JPanel p =
SwingFacade.createTitledPanel("Flight Path", fp);
SwingFacade.launch(p, "Flight Path for Shell Duds");
}
}
Running this class produces exactly the same results as the main() in the original
FlightPanel class. But now, you have a more reusable toolkit and a Swing facade that
provides standard components and simplifies launching Swing applications.
Facades, Utilities, and Demos
A facade class may have all static methods, as is the case with the SwingFacade class
provided in the solutions. Such a class is called a utility in UML (Booch, Rumbaugh, and
Jacobson 1999). A demo is an example that shows how to use a class or a subsystem. As
such, demos provide much of the same value as facades.
CHALLENGE 4.2
Write down two differences between a demo and a facade.
Search WWH ::




Custom Search