Java Reference
In-Depth Information
public static void listen(Frame f) {
f.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
This code registers with the frame an instance of an anonymous WindowAdapter subclass
that overrides the windowClosing() method. The value of the WindowAdapter class is
that it makes it easy to create a subclass that reacts to only the relevant window events.
SOLUTION 2.5
The advantage of placing constants in an interface is that a class that implements the interface
can use the constants as if it had inherited them from a superclass. To make the classification
constants available to a class, declare that the class implements
the ClassificationConstants interface. Then you can change secureOrder() to:
public void secureOrder(Firework f /*, etc. */)
{
//...
if (f.classification == DISPLAY)
{
// issue warning
}
else
{
// proceed
}
}
The difference is that you can now refer to the constant as DISPLAY instead of
Classification.DISPLAY .
Search WWH ::




Custom Search