package rakuseven.G1;
 
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.SurfaceHolder.Callback;
import android.widget.ImageButton;
import android.app.*;
import android.content.*;
import android.view.*;
import android.view.View.*;
import android.webkit.*;
import android.widget.*;
public class RandomRun extends SurfaceView implements Callback {
 Context mCtx;
 class ImgThread extends Thread{
  private Bitmap mImgBack;
  private int cnt = 0;
  private SurfaceHolder mSurfaceHolder;
  int xpos = 10;
  int ypos = 20;
  int BGmove = 0;
  int CENTER = 4;
  Horses horses;
  public ImgThread(SurfaceHolder surfaceHolder, Context context){
   mSurfaceHolder = surfaceHolder;
   Resources res = context.getResources();
   mImgBack = BitmapFactory.decodeResource(res, R.drawable.bglong);
   horses = new Horses(context);
   
  }
  public void run(){
   for(int i = 0 ; i < 5; i++)
    horses.Horse[i].start();
   
   while(true){
    boolean changed = false;
    
    for(int i = 0 ; i < 5; i++){
     if(horses.Horse[i].preStep != horses.Horse[i].LOCATION){
      changed = true;
     }
    }
    Canvas canvas = null;
    if (changed) {
     try {
      canvas = mSurfaceHolder.lockCanvas(null);
      synchronized (mSurfaceHolder) {
       canvas.drawBitmap(mImgBack, BGmove, 0, null);
       cnt++;
       for (int i = 0; i < 5; i++) {
        if(horses.Horse[CENTER].LOCATION < 200){
         xpos = horses.Horse[i].LOCATION;
        }else if(horses.Horse[CENTER].LOCATION >= 200 && horses.Horse[CENTER].LOCATION <= 1100){
         xpos = 200 - (horses.Horse[CENTER].LOCATION -horses.Horse[i].LOCATION);
         BGmove = 200 - horses.Horse[CENTER].LOCATION;
        }else if(horses.Horse[CENTER].LOCATION > 1100){
         xpos = horses.Horse[i].LOCATION - 900;
        }
        horses.Horse[i].mHImage[horses.Horse[i].FRAME % 2].setBounds(xpos, ypos + (i * 40),xpos + 100, ypos + (i * 40) + 100);
        horses.Horse[i].mHImage[horses.Horse[i].FRAME % 2].draw(canvas);
       }
       Paint paint = new Paint();
       paint.setAntiAlias(true);
       paint.setTextSize(18);
       if(horses.NUMBER > 5){
        canvas.drawText("- END -", 200, 100, paint);
        for(int i = 1; i <= 5; i++){
         for(int j = 0; j < 5; j++){
          if(i == horses.Horse[j].RANK){
           canvas.drawText(i+"�� : "+horses.Horse[j].NAME, 170, 100+(i*22), paint);
          }
         }
        }
        break;
       }
       sleep(1);
      }
     } catch (InterruptedException e) {
      e.printStackTrace();
     } finally {
      if (canvas != null) {
       mSurfaceHolder.unlockCanvasAndPost(canvas);
      }
     }
    }
    changed = false;
   }
  }
 }
 private ImgThread thread;
 public RandomRun(Context context, AttributeSet attrs) {
  super(context, attrs);
  // TODO Auto-generated constructor stub
  mCtx = context;
  SurfaceHolder holder = getHolder();
  holder.addCallback(this);
  thread = new ImgThread(holder, context);
  setFocusable(true);
 }
 
 @Override
 public void surfaceChanged(SurfaceHolder holder, int format, int width,
   int height) {
  // TODO Auto-generated method stub
 }
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
  // TODO Auto-generated method stub
  thread.start();
 }
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) {
  // TODO Auto-generated method stub
  boolean retry = true;
  while(retry){
   try{
    thread.join();
    retry = false;
   }catch(InterruptedException e){
   }
  }
 }
 @Override
 public void onCreate(Bundle savedInstanceState) {
  
  super.onCreate(savedInstanceState);
  setContentView(R.layout.title);
  
  ImageButton Imagebutton17 = (ImageButton) findViewById(R.id.BTN_START);
  Imagebutton17.setOnClickListener(this); //�ڷ� ��ư }
  public void onClick(View v) {
   
   if (v.getId() == R.id.BTN_START) {
    Intent intent = new Intent(getApplicationContext(),
      G1.class);
    
    startActivity(intent);
   }

public class RandomRun extends SurfaceView implements Callback{ 에서
public class RandomRun extends Activity implements OnClickListener{ 로 바꾸면 되는데 ... 그럼

 private ImgThread thread;
 public RandomRun(Context context, AttributeSet attrs) {
  super(context, attrs);
  // TODO Auto-generated constructor stub
  mCtx = context;
  SurfaceHolder holder = getHolder();
  holder.addCallback(this);
  thread = new ImgThread(holder, context);
  setFocusable(true);
 }
 
 @Override
 public void surfaceChanged(SurfaceHolder holder, int format, int width,
   int height) {
  // TODO Auto-generated method stub
 }
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
  // TODO Auto-generated method stub
  thread.start();
 }
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) {
  // TODO Auto-generated method stub
  boolean retry = true;
  while(retry){
   try{
    thread.join();
    retry = false;
   }catch(InterruptedException e){
   }
  }
 }

이부분이 싹다 에러가 납니다 .. ㅠㅠ
같이 선언해서 쓰는 방법이 있나요 혹시??
public class RandomRun extends SurfaceView,  Activity   implements Callback,  OnClickListener{
이런 방법이나 ... ;; 안되죠 역시 .. 해결 방법 꿈같은 해결방안 부탁드릴게요 .. ㅠ