Overview Schedule Announcements Resources Assignments Home

CSC 121: Computer Science I, Spring 2005

Lab 9

Laboratory 9 - Pattern Recognition: Mouse Events, Arrays

Goals:
To prepare for project 4: Processing unistroke characters made with a pen or mouse. Mouse events, arrays of Circles.
Getting started:
The Steps of the Lab:
  1. Open the eventsdelmouse project.
    Do

    Practice with arrays. Open the ArrayPractice class. This class has one field, an int array called numbers. The constructor creates the array with length 20 and puts a random number in each cell of the array. There is also a reset() method that can be used to generate another set of cell values for the array. Write and test the following methods:

    • getMax() - returns the largest value in the array
    • getMin() - returns the smallest value in the array
    • getMaxIndex() - returns the index of the largest value in the array
    • display() - displays each element in the array
    • displace() - subtracts the smallest value from each element in the array
    Observe

    Practice with mouse events. Close ArrayPractice and open the Mouse class. Open the class in the editor and observe the mouse event methods. Create an instance of the Mouse class and invoke the start method. As you move the mouse around, observe the events that occur. Click the mouse and observe the three events that occur. Now uncomment the statement "System.out.println(event);" in the mouseMoved method. Create an instance of the Mouse class, invoke the start method and observe the results as you move the mouse. Repeat this step by uncommenting the same statement in the mouseDragged method. Create a Mouse class instance and observe what happens when you drag the mouse.

    Do

    Close the Mouse class and open the Driver class. Create a Driver instance and invoke the start method. Now drag the mouse and observe the results. This class is using an array of circles, myCircle, to represent captured mouse events. Write and test the following methods:

    • getMin() - returns the y-position of the Circle nearest to the top of the canvas.
    • displace() - use the moveTo method of the Circle class to move each circle in the myCircle array vertically toward the top of the canvas getMin() units.
Overview Schedule Announcements Resources Assignments Home

Valid HTML 4.01!Valid CSS!DePauw University , Computer Science Department , Spring 2005
Maintained by Brian Howard ( bhoward@depauw.edu ). Last updated