Homework 12

Rewrite your program for Lab10 using a graphical user interface that displays the report in a JTextArea. Also, modify the report so that it displays the average of the SAT scores beneath the table (i.e., the average math score, the average verbal score, and the average combined score). The output should be formatted as illustrated in the sample run shown here:

Sample Run

As usual, the application window has to be resized to make it look like the illustration above. My text field has a width of 30 and my text area has a height of 10 and a width of 50. I am using a plain, size 11, mono-spaced font in my text area.

As you read the records from the data file, you will need to maintain two sums (the sum of the math scores and the sum of the verbal scores) and a counter to count the number of records. After all of the data has been read, you can find the sum of the combined scores by just adding the sum of the math scores and the sum of the verbal scores.

Miscellaneous GUI Specifications

On the two buttons, the letters indicated in the sample run above should be underlined. This will allow the user to enter the Alt-O sequence to open the specified file. That is, entering the Alt-O sequence on the keyboard has the same effect as clicking the Open button with the mouse. Similarly, the user can enter the Alt-X sequence to exit the application.

The text field should add this application as an action listener. This will allow the application to detect when the user taps the Enter key while in the text field. Clicking the Enter key while in the text field indicates that the user has finished entering the file name and the program should respond just as if the user clicked the "Open" button (or entered the Alt-O keystroke combination).

The text area should be within a JScrollPane object in which there is never a horizontal scroll bar and there is always a vertical scroll bar (whether it is needed or not). I'll give you a hint. You must set the horizontal scroll bar policy of the JScrollPane object so that it never displays a horizontal scroll bar and you must set the vertical scroll bar policy of the JScrollPane object so that it always displays a vertical scroll bar. As you would expect, there are methods for performing these two tasks but you'll have to figure out what they are.

Bonus Points

I'll give you 5 bonus points if you create the graphical user interface using a GridBagLayout rather than a FlowLayout. Your interface should look like this when your application begins execution:


Submitting Your Work

Submit your Hmwk12.java application as an attachment to an email message whose subject is "Hmwk12".