J
justineee
if (!(dictionary.contains(getInputAdd)))
{
if (!(getInputAdd.equals("")))
{
word = new Word (getInputAdd);
dictionary.add(word);
inputAdd.setText("");
aCtr++;
if (aCtr==(inputConfigQty))
{
addButton.setEnabled(false);
inputFind.setEditable(true);
inputDelete.setEditable(true);
resetButton.setEnabled(true);
displayButton.setEnabled(true);
sortButton.setEnabled(true);
findButton.setEnabled(true);
deleteButton.setEnabled(true);
clearButton.setEnabled(true);
sortButton.setEnabled(true);
sortDecButton.setEnabled(true);
displayButton.setEnabled(true);
sortDecButton.setEnabled(true);
displayAllButton.setEnabled(true);
addDefButton.setEnabled(true);
delDefButton.setEnabled(true);
addDefOk.setEnabled(true);
delDefOk.setEnabled(true);
}
}
else
mBox.setText("Please put\na word.");
}
else if (dictionary.contains(getInputAdd))
mBox.setText(getInputAdd+" is already\nin the
dictionary.");
}
My program lets the user add words to store it like a customized
dictionary. However, he/she can't add the same words so I used the
contains method (dictionary is an ArrayList of a class I create Word,
ArrayList<Word>) to check if the dictionary already have the word. But
when I try it, the program still lets me add the same word so it
doubles up.
When I add 'a', it is in the dictionary. Then when I add 'a' again,
it's supposed to do this:
else if (dictionary.contains(getInputAdd))
mBox.setText(getInputAdd+" is already\nin the
dictionary.");
It doesn't work for me, it will still add 'a' many times. By the way,
getInputAdd is a String.
Help please. Thanks.
{
if (!(getInputAdd.equals("")))
{
word = new Word (getInputAdd);
dictionary.add(word);
inputAdd.setText("");
aCtr++;
if (aCtr==(inputConfigQty))
{
addButton.setEnabled(false);
inputFind.setEditable(true);
inputDelete.setEditable(true);
resetButton.setEnabled(true);
displayButton.setEnabled(true);
sortButton.setEnabled(true);
findButton.setEnabled(true);
deleteButton.setEnabled(true);
clearButton.setEnabled(true);
sortButton.setEnabled(true);
sortDecButton.setEnabled(true);
displayButton.setEnabled(true);
sortDecButton.setEnabled(true);
displayAllButton.setEnabled(true);
addDefButton.setEnabled(true);
delDefButton.setEnabled(true);
addDefOk.setEnabled(true);
delDefOk.setEnabled(true);
}
}
else
mBox.setText("Please put\na word.");
}
else if (dictionary.contains(getInputAdd))
mBox.setText(getInputAdd+" is already\nin the
dictionary.");
}
My program lets the user add words to store it like a customized
dictionary. However, he/she can't add the same words so I used the
contains method (dictionary is an ArrayList of a class I create Word,
ArrayList<Word>) to check if the dictionary already have the word. But
when I try it, the program still lets me add the same word so it
doubles up.
When I add 'a', it is in the dictionary. Then when I add 'a' again,
it's supposed to do this:
else if (dictionary.contains(getInputAdd))
mBox.setText(getInputAdd+" is already\nin the
dictionary.");
It doesn't work for me, it will still add 'a' many times. By the way,
getInputAdd is a String.
Help please. Thanks.