JAVA   63
Scribble
Guest on 9th February 2023 03:09:45 AM


  1. import objectdraw.*;
  2. import java.awt.*;
  3.  
  4. // This program allows its user to draw simple lines on the screen
  5. // using the mouse as if it were a pencil.
  6. public class Scribble extends WindowController {
  7.  
  8.     Location previousPosition;   // Last known position of mouse
  9.  
  10.     // When the mouse button is depressed, note its location
  11.     public void onMousePress( Location pressPoint) {
  12.         previousPosition = pressPoint;
  13.     }  
  14.  
  15.     // Connect current and previous mouse positions with a line
  16.     public void onMouseDrag( Location currentPosition) {
  17.         new Line( previousPosition, currentPosition, canvas);
  18.         previousPosition = currentPosition;
  19.     }
  20.  
  21. }

Raw Paste

Login or Register to edit or fork this paste. It's free.