Drawing Lines with Mouse Input

Create an applet that will listen to Mouse Events so that whenever the user clicks down on the mouse and drags it and clicks up...a straignt line will be drawn from the points of where they clicked down and clicked up. Also, a current straigth line is drawn as the user is dragging the mouse from the start (clicked down) to the currently dragged position. You may assume that a maximum of 20 lines will be draw on the Applet's graphics.
  1. you must create a Java applet with a class that extends the Applet class. (you must import the java.applet package).
  2. this applet must also implement the MouseListener interface to get the events when the mouse is clicked. (you must import the java.event package).
  3. this applet must also implement the MouseMotionListener interface to get the events when the mouse is being dragged. (you must import the java.event package).
  4. you should create an init() method that among other things must register the applet asa MouseListener and a MouseMotionListener,
  5. you should create an array of X, Y points belonging to the start and stop of each line entered in by the user. You can use the Point class that is part of java for this. Recall, you know that a maximum of 20 will be drawn.
  6. your method paint() must draw all of the straight lines sayve in the Start/Stop arrays. It must ALSO draw the current line being dragged out if one exists!


Please Draw lines with your mouse in the box below:
Need Java Enabled Browser

Solution