CSCI A201/A597

Lecture Notes 18

Spring 2000


Help with homework 7. Various ways of drawing with the mouse.

Let's review what we did last time. We looked at:

The first three topics are especially relevant to the assignment.

We also looked at the design stages of an application and at what it takes to transform it from a flow chart (or a diagram) into a program. The process is called implementation and it almost always has to come after the design phase. Very seldom it can be done at the same time with it, only when the problem is very simple. Issues of implementation need to be taken into account in the design phase, but the actual implementation, or coding in Java, can only take place after the design is done.

The diagram above is part of the planning process.

Here are some notations used:

Columns and lines in the grid have been numbered for convenience. There are 11 columns and 7 lines in the grid. In your program you should be using variables instead of 11 and 7, and put any values that you want in them, thus being able to work with any grid size you want.

It could be convenient to make a square grid in which case one variable size could be all you need (and that should bring you memories of the practical).

Now the design of the assignment.

Step 1
Create a drawing window.

Step 2
Draw the grid with your choice of xL, yL, size and w

Step 3
Get mouse input. Report xM and yM.

Step 4
Knowing xL, yL and w, make the mouse report the column and the line of the square that it is being clicked on (if any). If the mouse is clicked outside the grid report that.

Step 5
Adjust the output to report the coordinates of the top left corner of the square that is located in the line and column where the mouse is being clicked on, and draw a filled red square of size w positioned with the top left corner in the point where the mouse was clicked. In step 6 change this positioning the red square properly.

These steps will be shown today in class, in an actual implementation.

Time permitting we will be showing you another application.

If we don't have time we'll just have to delegate that to the lab notes.


Last updated: Mar 9, 2000 by Adrian German