package guistuff;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.Timer;

import breadboards.Breadboard;

public class AnimationTest extends Breadboard {
  
    public static void main(String[] args) {
      new AnimationTest();
    }
    
    Timer timer;
    Animation walkingMan;
    Animation explosion;
    
    public AnimationTest() {
      this.getPanel(this.NORTH).remove(this.getTextArea());
      this.getPanel(this.SOUTH).remove(this.getLabel());
      this.getPanel(this.SOUTH).remove(this.getTextField());
      this.getPanel(this.SOUTH).remove(this.getButton2());
      this.getButton1().setText("Jog!");
      this.setCenterPanelSize(500,500);
      this.setBackground(Color.WHITE);
    }
    
    public void init() {
        this.getPanel(CENTER).addMouseListener(new MouseListener() {
            public void mousePressed(MouseEvent e) {
                explosion = new Animation("guistuff/explosionframes/", 
                           Animation.REMOVES_ITSELF_WHEN_COMPLETE);
                explosion.setLocation(e.getX(),e.getY());
                AnimationTest.this.add(explosion);
            }

            public void mouseReleased(MouseEvent e) {}
            public void mouseClicked(MouseEvent e) {}
            public void mouseEntered(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
            });
        
        timer = new Timer(30, new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                walkingMan.move(-5, 0);
                if (walkingMan.getX() < -200) {
                    walkingMan.setLocation(600,200);
                }
            }});
    }
    
    public void onButton1Click() {
        walkingMan = new Animation("guistuff/walkingmanframes/", 
                                    Animation.LOOPS);
        walkingMan.setLocation(600,200);
        this.add(walkingMan);
        timer.start();
    }
}
