package snake;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */
class snakeBody{
  static final int NORTH = 4;
  static final int SOUTH = 3;
  static final int WEST = 2;
  static final int EAST = 1;
  int orientation = EAST;
  Point head = new Point(10, 50);
  JLabel body = new JLabel("$");
  public snakeBody(){
    body.setLocation(head);
    body.setSize(10, 10);
    body.setBackground(Color.red);
  }
  public void relocation(){
    switch(orientation) {
      case EAST :
        head.setLocation(head.getX()+1, head.getY());
        body.setLocation(head);
    }
  }

}
class groundPanel extends JPanel{
  snakeBody snake = new snakeBody();

  public groundPanel(){
    setBackground(Color.yellow);
    setLayout(null);
    add(snake.body);
    this.setFocusable(true);
    //this.requestFocus();
    this.addKeyListener(new myKeyListener());
  }

  //public void paint(Graphics g){

  //}
  class myKeyListener extends KeyAdapter {
    public void keyPressed(KeyEvent e){
      switch(e.getKeyCode()) {
        case KeyEvent.VK_RIGHT :
          snake.orientation = snakeBody.EAST;
          snake.relocation();
      }
    }
  }
}

public class snakeFrame extends JFrame{
  public snakeFrame() {
    this.setContentPane(new groundPanel());
    setSize(500, 500);
    setVisible(true);
    this.setResizable(false);
  }
  public static void main(String[] args) {
    snakeFrame snakeFrame1 = new snakeFrame();
  }

}
