import java.awt.*;
import java.awt.event.*;

public class PacMan extends Canvas implements ActionListener {

  //public Dimension getPreferredSize () { return new Dimension(30,30); }

  //public Dimension getMinimalSize () { return getPreferredSize(); }

  public PacMan () {
    setSize(30,30);
  }

  public void paint (Graphics g) {
    g.setColor(Color.black);
    g.fillOval(0,0,30,30);
    g.setColor(getBackground());
    g.fillPolygon(new int[]{15,30,30}, new int[]{15,0,30}, 3);
  }

  public void actionPerformed (ActionEvent e) {
    Point l = getLocation();
    if ("left".equals(e.getActionCommand())) {
      l.x -= 15;
    }
    else if ("right".equals(e.getActionCommand())) {
      l.x += 15;
    }
    else if ("up".equals(e.getActionCommand())) {
      l.y -= 15;
    }
    else if ("down".equals(e.getActionCommand())) {
      l.y += 15;
    }
    setLocation(l);
  }
}

