Homework 7 (NameSurfer2) FAQ

Q: HW7 NameSurfer2 is based on HW6 NameSurfer. But what should I do if I never completed HW6? Do I have to take a 0 on HW7?
A: No; you can still complete NameSurfer2. In the provided starter ZIP, we have included a solution to HW6 that you can use as a basis for your HW7. We provide you the compiled version of our solution only, not its source code. (The starter ZIP was updated to contain this functionality on Sat 5/31 at 10:30am; if you got it before that, please re-download.) To keep our solution from colliding with your own possible solution to NameSurfer, we put our solution in the package stanford.cs106.namesurfer.

To use our provided NameSurfer solution, you must import individual classes into your file. For example, to use our class NameSurfer as the basis for your own NameSurfer2, you should write:

import stanford.cs106.namesurfer.NameSurfer;     // use instructor's solution
import stanford.cs106.namesurfer.NameGraph;      // use instructor's solution
import stanford.cs106.namesurfer.NameDatabase;   // use instructor's solution
import stanford.cs106.namesurfer.Person;         // use instructor's solution

public class NameSurfer2 extends NameSurfer implements ResizeListener {
    ...

You MUST import each class individually as shown above. Don't use the .*; syntax; that will not work properly.

The HW7 spec talks about making fields protected so that the subclasses can see/modify them. Our own NameSurfer class solution doesn't have any protected fields, but it does provide accessor methods you can call to access its various GUI components:

protected NameDatabase getDatabase() Returns the name database stored in the NameSurfer.
protected NameGraph getGraph() Returns the name graph being displayed by the NameSurfer.
protected JTextField getNameField() Returns the text field the user types names into.
protected JRadioButton getMaleRadioButton() Returns the radio button labeled "Male".
protected JRadioButton getFemaleRadioButton() Returns the radio button labeled "Female".
protected JStringList getNamesShownList() Returns the JStringList of names being shown.

So, for example, if you wanted to tell the name graph to update itself in your NameSurfer2 code, you could write:

getGraph().updateGraph();
Q: I am using the instructor-provided solution. For the Remove feature, how do I implement the deselect method of the NameDatabase when I don't have the source code to that class?
A: You basically can't. That method is already provided for you in our NameDatabase, and you can just call it. You should still implement the Remove feature, but you don't need to write the deselect part of it.
Q: I am using the instructor-provided solution and I see an error about, "FileNotFoundException: res/icons/bystate.gif". What is that? How do I fix it?
A: That was a bug in our provided solution code. You can try re-downloading the starter ZIP or grabbing the following JAR file and putting it into your lib/ directory of your Eclipse project: cs106a-namesurfer-solution-files.jar
Q: What text should be in the Meaning text area after a name is removed, or after the names are cleared?
A: It should become empty/blank.
Q: Why do I see two action events whenever the user clicks on the JStringList? Is it a bug in my code?
A: The string list generates an action event every time its selection changes. Somewhat counter-intuitively, this happens twice per click: once when the previously selected item de-selects itself, and again when the newly selected item becomes selected. It isn't anything in your code. It should be something that your code can ignore, because the response to action events on the string list should be the same no matter how many times the event occurs; just look up the name's meaning and put that text into the text area, replacing any previous text.
Q: Why do I keep getting a NullPointerException?
A: Well, there can be any number of reasons. For starters, please read through the red exception text at the bottom of Eclipse and find the top-most line that comes from your code files. Go to that line and look at what it is doing. Think about, how could a value on that line possibly be null?

On this assignment, a common reason for null pointer errors is because you are trying to access the selected value in a JStringList. When no value is selected, it returns null. Don't try to call string methods like toUpperCase or substring on a null value. Make sure to test for null before doing so.

This document and its content are copyright © Marty Stepp, 2014. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.