CS365 Spreadsheet Interface Project Assignment
My interpreter notes can be found here.
In this assignment your team is going to create a user interface using
Swing widgets for the
spreadsheet interpreter that you wrote in the previous assignment.
A minimal acceptable interface is shown below:
It contains the following items:
Your team should feel free to do some creative design for extra credit
on this assignment. Some of the opportunities include:
- An 11x11 grid of JLabels or JTextFields (I used JTextFields
and set the editable property to false).
- The top row contains fixed column
labels with the values a-j
- The leftmost column contains
the row subscripts 0-9.
- The remaining labels should display the current
value of the cell at that location (e.g., the label at
b3 should display the current value of the cell b3).
- If the formula cannot be evaluated because it
depends on an undefined cell, then
the cell's value should be displayed as "undef".
- If the cell has never been assigned a formula, its
value should be blank.
- A cell's numeric value should be displayed with
two decimal places. You can format a floating point
number as a string using the String command:
String.format(format string, args)
String formattedString = String.format("%3.2f", 65.3868);
- A text box for entering new formulas. For this assignment
you may pass the new formula to either your antlr parser, or
to one that I will provide. If the formula is correctly
parsed and evaluated, then the text box should be cleared and
the cell's new value should appear in the spreadsheet.
When a parse error occurs,
either because of a syntax error or a semantic error, your
interface should pop up a dialog box describing the error. Your
program should not clear the text box in this case, so
that the user has an opportunity to correct the user's error.
My interpreter notes describe the
exceptions thrown by my code.
- A button for explaining why a cell's value is displayed as
"undef". To utilize this feature, the user will need to select
a cell, and then press the button. Your interface should pop
up a dialog box that names the undefined cell on which this
formula depends. For example, if the formula is
"c = a + b" and b is undefined, then
your interface will show that c is undefined. When
the use clicks the inquiry button, your interface will pop up
a dialog box saying that b is undefined.
- A quit button for exiting the spreadsheet.
- Being able to edit the column labels before any formula has been
assigned to a cell in that column.
- Adding new columns to the end of the spreadsheet.
- Entering a new formula directly into a cell (you will need to
use JTextFields to represent each cell rather than JLabels).
This would probaby work only with non-generic formulas, although
you are free to try to work out a design for generic formulas
as well. Since the left hand side of the formula is known, the
user should just be able to enter the formula (e.g., b + c)
without specifying the left hand side variable. You can
append the left hand side variable and an equal sign to the
formula entered by the user and then pass the string to the
- Using a JTable, rather than JTextFields or JLabels, for the
- Feel free to use your imagination to add other features, but
please document them in a README.txt file.
The previous section described most of the required behaviors
for this interface. However, please make sure that
your interface also supports the following behaviors:
- When a formula is entered in the formula text box, the cell(s)
it is assigned to should be updated, as well as any cells that
depend on the cell(s) with the new formula. If you use my
parser, you can call Cell.updateCells() to re-evaluate
all the cells and bring their values up to date. Then
you can simply traverse through
each location in your spreadsheet grid, request the value of that
cell, and assign it to the appropriate JLabel or JTextField.
- When the user mouse clicks on a cell, the formula associated
with that cell should appear in the formula textbox (the formula
may be a simple number). If you use my interpreter, the
Cell class has a method named setFormulaExpression
that you can use to store a formula's text string with a cell,
and a method named getFormulaExpression that you can
use to retrieve this string. You will need to call
setFormulaExpression on each cell that is assigned
a formula by the parser. My parser will return a linked list
of cell objects, and you can iterate through them and set each
one to point to the string for this formula. Antlr does not
provide a way of getting at the original string that is passed
to the parser, so the parser cannot be responsible for storing
the formula string into a cell.
- When the user press the quit button, the spreadsheet should
A sample executable with the minimal interface that I just described
is available as a jar file at
This jar file will only work on the CS machines,
because it depends on
the antlr implementation on the CS machines. If you want
to make it work on your machine, you will need to copy my class
files from /home/bvz/cs365/project/project4/formula and then
jar it up with your own version of antlr.
- Place your code in a package named formula.
- Your main class should be called Spreadsheet.
- Jar up your .g, .java, and .class files and include a manifest.txt file with the following lines:
- Use the 365_submit script and type "p4".