import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Bricks extends Applet implements ActionListener
{

     private Button grow, shrink, left, right, up, down, rotate;
     private Brick rectBrick;

     public void init()
     {

        grow = new Button("Grow");
        add(grow);
        grow.addActionListener(this);

        shrink = new Button("Shrink");
        add(shrink);
        shrink.addActionListener(this);

        left = new Button("Left");
        add(left);
        left.addActionListener(this);

        right = new Button("Right");
        add(right);
        right.addActionListener(this);

        up = new Button("Up");
        add(up);
        up.addActionListener(this);

        down = new Button("Down");
        add(down);
        down.addActionListener(this);

        rotate = new Button("Rotate");
        add(rotate);
        rotate.addActionListener(this);

        rectBrick = new Brick(150,100,80,30);
    }

    public void actionPerformed(ActionEvent event)
    {

       if (event.getSource()==grow)
         rectBrick.grow();

       if (event.getSource()==shrink)
         rectBrick.shrink();

       if (event.getSource()==left)
         rectBrick.left();

       if (event.getSource()==right)
         rectBrick.right();

       if (event.getSource()==up)
         rectBrick.up();

       if (event.getSource()==down)
         rectBrick.down();

       if (event.getSource()==rotate)
         rectBrick.rotate();

       repaint();
    }

    public void paint (Graphics g)
    {

      rectBrick.display(g);
    }
}

class Brick
{
   private int xPixel, yPixel;
   private int xPosition, yPosition;

   public Brick (int xCoord, int yCoord,int firstX, int firstY)
   {
      xPixel = firstX;
      yPixel = firstY;
      xPosition = xCoord;
      yPosition = yCoord;
   }

   public void grow()
   {
     xPixel = xPixel + 20;
     yPixel = yPixel + 20;
   }

   public void shrink()
   {
     xPixel = xPixel - 20;
     yPixel = yPixel - 20;
   }

   public void left()
   {
   
     xPosition = xPosition - 20;
   }

   public void right()
   {
 
     xPosition = xPosition + 20;
   }

   public void up()
   {
     yPosition = yPosition - 20;
   }

   public void down()
   {
     yPosition = yPosition + 20;
   }

   public void rotate()
   {
       xPixel = xPixel - 50;
       yPixel = yPixel + 50;      

   }

   public void display(Graphics g)
   {
      g.drawRect(xPosition, yPosition,xPixel, yPixel);
   }
}
