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();
deselect
method of the NameDatabase
when I don't have the source code to that class?
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.
JStringList
?
Is it a bug in my code?
NullPointerException
?
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.