//draw a dot and make it appear to move towards you
//modified from computer insights Arnold UTM
//mbooth 2005 12

//import section
import java.awt.*;  //abstract windowing toolkit - contains graphics
import javax.swing.*; //gui
import java.awt.event.*;//events


//moving dot inherits JPanel and ActionListener (multiple inheritance)
public class ImprovedAnimationPanel extends JPanel implements ActionListener
{
    //fields
    private int intX, intY;//coordinates

    //constructor - make GUI and initialize coordinates
    public ImprovedAnimationPanel()
    {
		//variables
        Timer timer;//timing
        Dimension dim;//dimension

        //initialize coordinates
        this.intX=0;
        this.intY=0;

        //set up dimension
        dim = new Dimension(150, 200);

        // set up size and colour of window
		setBackground(Color.blue);
		setMinimumSize(dim);

		//set up timer
		timer = new Timer(1000, this);//with 1000 delay, and listener
		timer.start(); //start timer
	} //end of improved animation panel constructor

    //paintComponent method overrides JPanel
	public void paintComponent(Graphics g)
    {
        //display background and filled circle
       	super.paintComponent(g); //paint background override
		g.fillOval(this.intX+10,this.intY+10,this.intX+3,this.intX+3);
	}

    //moving circle method
	public void actionPerformed(ActionEvent e)
    {
		//action
		this.intX=(this.intX+1)% 100;//change x,y
		this.intY=(this.intY+1)% 100;
		repaint();  // Schedule a repaint of screen
	}//end of action
}//end of class
