import java.awt.*;
import javax.swing.*;
import java.math.*;

public class Monstro extends Thread{
   private int PosX, PosY, X = 5, Y = 5;
   private JLabel Monstro;
   private JLabel Sonic;
   
   public Monstro(JLabel Monstro, JLabel Sonic){
      this.Monstro = Monstro;
      this.Sonic = Sonic;
      PosX = (int)(Math.random()*400)+200;
      PosY = (int)(Math.random()*200)+200;
   }
   
   public void run(){
      while(true){
         
         try{this.sleep(100);}catch(Exception e){}
         
         PosX += X; 
         if(PosX>700)X=-5;
         if(PosX<1)X=5;
         
         PosY += Y; 
         if(PosY>500)Y=-5;
         if(PosY<1)Y=5;

         Monstro.setLocation(PosX, PosY);
         
         if(Math.abs(Sonic.getX()-Monstro.getX())<100 &&
            Math.abs(Sonic.getY()-Monstro.getY())<100)
         {
            System.out.println("Se f....");
            break;
         }
      }
   }
}