This is the final version. It is still your responsibility to
check back here for any changes or updates.
.class files for Sample Solution for hw 7 are in the public
directory.
This assignment was mistakenly listed as hw
6 for a brief time. It is really hw 7.
Required reading: Savitch text Chapters 12-14. (We will
return to cover Chapter 9 in assignment #8. Section 10.2 of Chapter
10 is not covered in this class.) This exercise should be done
using only the material from Chapters 1 through 8, plus 11-14.
Due dates: Check the Announcements.
Note you can do this and take an interview without turning in
the assignment, as long as it is before the turnin deadline (and
until the deadline is announced it is definitely before the deadline.)
Programming: You may work in teams of two students, but
once you form a team, you cannot change the team for this assignment.
You may work alone if you prefer.
Part I:
Rewrite the program in Display 12.15/page 813 so that it has all
of the following changes:
i. Change the class name to MemoSaver2.
ii. There are four buttons instead of five and they are arranged
in one row as follows:
------- ------- Save-------
Get------- Clear-------
Exit
---The buttons are still at the bottom
of the GUI with the text area above it.
iii. When the user clicks Save another window appears asking the
user if it should be saved as memo 1 or memo 2. This window will
have buttons labeled:
------- ------- Memo 1-------
Memo 2------- Cancel
------- The buttons have the obvious
meaning. When the user saves the text as memo 1, the text area
changes so that it says "Memo 1 saved.", and when memo 2 is saved,
it changes to "Memo 2 saved." (See Self-Test Exercise 38 on page
818 for a hint.)
iv. When the user clicks Get another window appears asking the
user if the user wants to get memo 1 or memo 2. This window will
have buttons labeled:
------- -------
Memo 1 ------- Memo 2-------
Cancel
------- The buttons have the obvious
meaning.
v. When the "Exit" button is clicked, the program ends and the
window goes away. The close-window button also ends the program.
So, the "Exit" button and the close-window button perform the
same action.
vi. In addition to the default constructor, there is also a constructor
of the following form:
public MemoSaver2(int lineCount, int charCount)
When this constructor is used, it produces the same display except
that the text area has dimensions of lineCount number of lines
and charCount number of characters per line.
vii. The text area has line wrap so that if more characters are
entered than will fit on the line, then the extra characters automatically
go on the next line.
viii. The method main constructs two windows, one using the default
constructor and one using the above constructor with parameters
5 and 60 in that order.
Part II:
Write a GUI using Swing that behaves as follows. When the program
is run a window appears and asks the user how many lines and how
many characters per line, she or he wants for a memo saver. There
is a "Cancel" button, If the user clicks the Cancel button or
the close-window button, the program ends. More typically, the
users enters these two numbers in two text fields. There is a
button with the string "Continue" on it.
If the user clicks the "Continue" button, the window disappears
and another window appears. This second window is just like the
memo saver in Part I, except that the text area has the number
of lines and characters per line specified by the user in the
previous window. If the user clicks the "Continue" button and
the two text fields do not contain well formed positive integers
in the ran 1 to 100, then an error window appears. The details
of the error window are up to you, but the user must be allowed
to reenter the integers in some nice way.
Make the class MemoServer2 from Part I a private inner class of
your program class. This way your class will be self-contained.
You turn in the file from part II.
Last Update: Feb 18, 2003 (by Nakul
Verma)