/*
 * Test class to practice mouse inputs by drawing a circle where the user clicks.
 *
 * @author Jeff Borland
 * @date 11-12-9
 */

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DottedLine extends JApplet implements MouseListener,ActionListener
{

    public void init()
    {
        Container screen = getContentPane();
        screen.setBackground(Color.white);
        screen.setLayout (new FlowLayout() );
        addMouseListener(this);

    }

    public void paint (Graphics g)
    {
        super.paint(g);     
        g.fillOval(0,0,25,25);  
    }

    //when someone presses the mouse button
    int x1,y1=0;
    public void mousePressed(MouseEvent e)
    {      
        x1=e.getX();
        y1=e.getY();
    }

    //when someone releases the mouse button
    public void mouseReleased(MouseEvent e)
    {     
        int x2=e.getX();
        int y2=e.getY();
        double m=(y2-y1)*1.0/(x2-x1);
        int x=x1;
        Graphics g=getGraphics();
        while (x<x2)
        {
            int y=(int)(m*(x-x2)+y2);
            g.drawOval(x,y,0,0);
            x=x+5;
            
        }

    }

    // when the mouse enters the applet
    public void mouseEntered(MouseEvent e)
    {      

    }

    //when the mouse leaves the applet
    public void mouseExited(MouseEvent e)
    {      

    }

    //when the mouse button is clicked
    public void mouseClicked(MouseEvent e)
    {
     
    }

    public int findRandom (int start, int end)
    {
        int multiplier = end-start+1;
        int random = (int) (Math.random()*multiplier)+start;
        return random;
    }

    public void actionPerformed(ActionEvent thisEvent)
    {
        Object source = thisEvent.getSource();

        //now have if statements seeing finding out where the action occured

    }
}