Java Reference
In-Depth Information
launch.setBorder(
new CompoundBorder(
new LineBorder(Color.black, 4),
new CompoundBorder(
new BevelBorder(BevelBorder.RAISED),
new EmptyBorder(10, 10, 10, 10))));
JPanel p = new JPanel();
p.add(ignite);
p.add(launch);
SwingFacade.launch(p, " Borders");
}
}
If you think of painting a border as a behavior, you might design borders by using the
D ECORATOR pattern. On the other hand, if you think of borders as attributes, there is no need
compose behavior and no need for D ECORATOR .
Another feature of Java that might be mistaken for D ECORATOR is the ability to add behaviors
at runtime through the use of listeners. Suppose that you introduce a rollover effect for
a button by listening to the mouse, as the following code and Figure 27.9 show.
Figure 27.9. Listeners let you add behavior, such as rollover effects, without creating new
component subclasses.
package com.oozinoz.applications;
import com.oozinoz.ui.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class ShowListen
{
protected static JButton createButton(String label)
{
JButton b = new JButton(label);
b.setFont(SwingFacade.getStandardFont());
b.setFocusPainted(false);
return b;
}
public static void main(String[] args)
{
JPanel p = new JPanel();
p.add(createButton("Normal"));
final JButton b = createButton("Nifty");
Search WWH ::




Custom Search