01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package horstmann.ch06_scene1;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
   A program that allows users to edit a scene composed
   of items.
 */
public class SceneEditor
{
  public static void main(String[] args)
  {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final SceneComponent scene = new SceneComponent();

    JButton houseButton = new JButton("House");
    houseButton.addActionListener(event -> scene.add(new HouseShape(20, 20, 50)));

    JButton carButton = new JButton("Car");
    carButton.addActionListener(event -> scene.add(new CarShape(20, 20, 50)));

    JButton removeButton = new JButton("Remove");
    removeButton.addActionListener(event -> scene.removeSelected());

    JPanel buttons = new JPanel();
    buttons.add(houseButton);
    buttons.add(carButton);
    buttons.add(removeButton);

    frame.add(scene, BorderLayout.CENTER);
    frame.add(buttons, BorderLayout.NORTH);
    frame.setSize(300, 300);
    frame.setVisible(true);
  }
}