package com.rafkind.paintown.animator;

import java.util.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.Timer;
import javax.swing.event.*;

import org.swixml.SwingEngine;

import com.rafkind.paintown.animator.*;
import com.rafkind.paintown.*;

public final class DrawArea extends Canvas
{
	private BufferedImage img;
	private int img_x;
	private int img_y;
	private int offset_x;
	private int offset_y;
	private static int x=320;
	private static int y=200;
	private static int _delay=160;
	private int delay;
	private boolean _delayChanged;
	private BoundingBox attackArea = new BoundingBox(0,0,0,0);
	
	public Dimension getPreferredSize()
	{
		return new Dimension(640,480);
	}

	public void paint( Graphics g ){
      
			g.setColor( new Color( 0, 0, 0 ) );
			g.fillRect( 0, 0, 640, 480 );
			g.setColor( new Color( 255, 255, 0 ) );
			g.drawLine(0,350,640,350);
			if(img != null)g.drawImage( img, x + img_x + offset_x, y + img_y + offset_y, null );
			if(!attackArea.empty())attackArea.render(g, x + img_x + offset_x, y + img_y + offset_y);
	}
	
	public void setImage(BufferedImage i)
	{
		img = i;
	}
	
	public BufferedImage getImage()
	{
		return img;
	}
	
	public void setImageX(int x)
	{
		img_x += x;
	}
	
	public void setImageY(int y)
	{
		img_y += y;
	}
	
	public void setOffsetX(int x)
	{
		offset_x = x;
	}
	
	public void setOffsetY(int y)
	{
		offset_y = y;
	}
	
	public void setAttack(BoundingBox at)
	{
		attackArea = at;
	}
	
	public void resetData()
	{
		img_x = img_y = offset_x = offset_y = 0;
		attackArea = new BoundingBox(0,0,0,0);
	}
	
	public void setDelay(int d)
	{
		delay = d * 100;
		_delayChanged=true;
	}
	
	public int getDelay()
	{
		return delay;
	}
	
	public void resetDelay()
	{
		delay = _delay;
		_delayChanged = true;
	}
	
	public boolean delayChanged()
	{
		if(_delayChanged)
		{
			_delayChanged=false;
			return true;
		}
		return _delayChanged;
	}
	
	public DrawArea()
	{
		img = null; 
		_delayChanged = false;
		/*
		Action doAnim = new AbstractAction() {
			public void actionPerformed(ActionEvent e) {	
				repaint();
			}
		};
	
		new Timer(1000/60,doAnim).start();
		*/
	}
}

@@ -389,14 +389,18 @@
 nds 
-Canvas
+JComponent
 %0A%7B%0A%09
@@ -710,18 +710,17 @@
 0,0,0);%0A
-%09
 %0A
+
 %09public 
@@ -806,16 +806,25 @@
 id paint
+Component
 ( Graphi
@@ -835,18 +835,11 @@
  )%7B%0A
-      
 %0A%09%09
-%09
 g.se
@@ -866,25 +866,24 @@
 , 0, 0 ) );%0A
-%09
 %09%09g.fillRect
@@ -904,17 +904,16 @@
 80 );%0A%09%09
-%09
 g.setCol
@@ -944,17 +944,16 @@
  0 ) );%0A
-%09
 %09%09g.draw
@@ -975,17 +975,16 @@
 350);%0A%09%09
-%09
 if(img !
@@ -990,16 +990,20 @@
 != null)
+%0A%09%09%09
 g.drawIm
@@ -1066,17 +1066,16 @@
 ll );%0A%09%09
-%09
 if(!atta
@@ -1089,16 +1089,20 @@
 empty())
+%0A%09%09%09
 attackAr

use jcomponent instead of awts canvas