Homework 6: event handling, graphics, file output

Due Tuesday, 7 December, 23:59.

General instructions

In this assignment, you'll implement a portion of one of the experiments described in this paper by forumer IU Psychology student Cathy Sandhofer and her advisor, Linda Smith:

Sandhofer, C. M., and Smith, L. B. (2001). Why children learn color and size words so differently: evidence from adults' learning of artificial terms. Journal of Experimental Psychology: General, 130, 600-620.

(You don't have to read the paper. The reference is here just in case you want to look it up.)

In the experiments, Sandhofer and Smith were interested in why color adjectives such as red are learned differently than size adjectives such as big. In particular, color words are associated with one another before they are associated with the features that they represent, while the opposite is true for scalar adjectives like big. They investigated the possibility that this is related more to how the words are presented to children by parents than to anything about the meanings of the words themselves. They tested this idea in experiments with adults who were taught new adjectives referring to dimensions that they didn't already have labels for, for example, color saturation and brightness. Some of the subjects were taught the adjectives in one way ("comprehension"), and the others were taught in another way ("production)". For this assignment, we'll only implement a modified version of the comprehension condition. For each training trial in this condition, the subjects saw three figures and were asked "which one is X?", where X was one of the six adjectives being learned. They picked one and were then told the right answer. Later they were tested on figures they had never seen to see if they had learned the meanings of the adjectives. The comprehension task was supposed to resemble the way adjectives like "big", as opposed to adjectives like "red", were learned.

Download the program. It includes the source files you should start with and their compiled class files (in V1/), and the compiled version of the program as it should work if you've done all of the parts of the assignment (in V2/). Run the version in V2 to see what the program should do; the main() method is in the Adjectives class.

You will notice three components in the program's frame, a panel where the figures appear, a text area where text appears, and another panel containing the single button. When you click on the button, the instructions for the experiment appear in the text area. When you click again on the button (whose label has changed), the program randomly picks one of the six adjectives that is being taught, writes the question for this word in the test area, and draws three figures in the top panel, only one of which is correctly described by the given word. When you click on one of the figures, the program responds by circling the correct figure and printing in the text area whether your selection was right or wrong. It also records this result in a file called "responses". Clicking again (anywhere in the figure panel) brings up a new question and set of figures. The program repeats these two steps (presentation of figures and question for a randomly selected word, feedback about your response) until you click on the button again to stop the experiment.

For this assignment you will need to submit your whole program, that is, all of your source files. The number of files will depend on which classes you create. Be sure to insert comments in the code when appropriate and to indent the code properly.

To submit the assignment, first compress your program into a single file. Then go to the Vincent page for the class, and submit this file.

Details

Classes

The version of the program that you start with (in V1) has three classes, Adjectives, which just has the main() method; AdjFrame, which extends JFrame; and FigurePanel, which extends JPanel. Run this version of the program, and look at the .java files for the three classes. In AdjFrame, the three components within the frame are created with their appropriate sizes, the button gets an ActionListener, and the general behaviors of the program for when the button is clicked are specified in actionPerformed(). This class also has static methods for writing in the text area as well as for generating random integers. Within the FigurePanel class, there are constants for many things you will need (see below) as well as methods for drawing the three kinds of figures that appear in the FigurePanel: squares, circles, and regular pentagons.

Figures

The stimuli for the experiment are defined along four dimensions: saturation, brightness, hue, and shape. There are six possible values for each of the first two dimensions, and two each for the second two. The possible values of saturation, brightness, and hue are defined in the two-dimensional constant array COLOR_VALUES in the FigurePanel class. Note that the array contains floats; this is because the static Color method getHSBColor() that you will need to use to create colors from the values requires floats. The value of shape should always agree with the hue value for a figure; "red" figures (hue = 0.0) are always square, and "blue" figures (hue = 0.667) are always pentagons. The static figure-drawing methods in FigurePanel draw figures of particular sizes centered on particular points. Constants in the FigurePanel class specify possible values to use for the sizes and centers.

Labels

The adjectives used in the experiment are given as Strings in the constant array WORDS in the FigurePanel class. The first three of these label differences in saturation, one for every two possible values in the order that the values appear in the COLOR_VALUES array. The second group of labels refers to different values of brightness in the same way. For example, the adjective "RIF" labels the values 0.1 and 0.2 on the saturation dimension, and the adjective "MELGY" labels the values 0.7 and 0.8 on the brightness dimension. Hue and shape are distractor dimensions; that is, they are irrelevant for the the words being learned. So if you wanted to create a random instance of the word "ZUP", you'd randomly select either 0.8 or 1.0 for saturation, randomly select any of the six possible brightness values, and randomly select 0.0/SQUARE or 0.667/PENTAGON for hue and shape.

What you do

The assignment is divided into four parts. You get full credit if you complete the first two parts and extra credit if you complete any of the rest. I'm not giving you any suggestions about how to implement the program; you can do this however you want. You may want to create one or more additional classes; notice that my version of the final program has classes Figure and Stimulus. If you can't complete one part and want to go on to the next, make sure your comments make clear what your program can and can't do.

  1. Make it so that whenever the button is pressed after the instructions are displayed (that is, when the text on the button says "Start experiment") a random adjective is selected, a stimulus for this adjective and two distractor stimuli are created, a random position for the correct stimulus is selected, and the three figures are displayed in the FigurePanel. Since there is (as yet) no way for the subject to respond, the program will only be able to display a single set of figures each time it is run. (When the button is pressed again, it ends the experiment.)
  2. Make the FigurePanel respond to mouse clicks. When figures have been displayed in the FigurePanel and the user clicks on one of them, a message should appear in the text area saying which figure has been clicked on, for example, "You clicked on figure 2", and a new set of stimuli should be displayed. This continues until the button is pressed again, ending the experiment.
  3. Have the program evaluate the subject's response as in the final version of the program. It should print a message like "Which one is MELGY?" when the figures are displayed. Then when the subject clicks somewhere, it prints either "RIGHT" or "WRONG" and draws a circle around the correct figure. Under "RIGHT" or "WRONG", it prints "Click anywhere in the figure area to bring up another problem." When the subject clicks again, it displays three new figures in the FigurePanel and a new question in the text area.
  4. Have the program write the results of evaluating the subject's responses in a file called "responses". For example, if the adjective selected by the program is SLEE and the subject's response is wrong, it might print the following in the file: "WRONG: SLEE; selected: 0.4 0.7 0.0, correct: 0.2 0.6 0.0" where the numbers represent the values on the three color dimensions for the selected and correct figures. Remember to close the PrintWriter to the file when the experiment ends.

Home

Calendar

Coursework & grading

Assignments

Lecture notes

Other resources


IU home

IU CS home

Contact instructor