Java Reference
In-Depth Information
LISTING 12.6
continued
titleLabel =
new
JLabel ("The Koch Snowflake");
titleLabel.setForeground (Color.black);
increase =
new
JButton (
new
ImageIcon ("increase.gif"));
increase.setPressedIcon (
new
ImageIcon ("increasePressed.gif"));
increase.setMargin (
new
Insets (0, 0, 0, 0));
increase.addActionListener (
this
);
decrease =
new
JButton (
new
ImageIcon ("decrease.gif"));
decrease.setPressedIcon (
new
ImageIcon ("decreasePressed.gif"));
decrease.setMargin (
new
Insets (0, 0, 0, 0));
decrease.addActionListener (
this
);
orderLabel =
new
JLabel ("Order: 1");
orderLabel.setForeground (Color.black);
tools.add (titleLabel);
tools.add (Box.createHorizontalStrut (20));
tools.add (decrease);
tools.add (increase);
tools.add (Box.createHorizontalStrut (20));
tools.add (orderLabel);
drawing =
new
KochPanel (1);
appletPanel =
new
JPanel();
appletPanel.add (tools);
appletPanel.add (drawing);
getContentPane().add (appletPanel);
setSize (APPLET_WIDTH, APPLET_HEIGHT);
}
//-----------------------------------------------------------------
// Determines which button was pushed, and sets the new order
// if it is in range.
//-----------------------------------------------------------------
public void
actionPerformed (ActionEvent event)
{
int
order = drawing.getOrder();
if
(event.getSource() == increase)
order++;
else
order--;
Search WWH ::
Custom Search