I'm not sure I understood your question, but here are some comments on your code - I hope this helps
In the draw method, instead of catching the NullPointerException and ignoring it, you should check if the value is null. Once the exception is thrown the following lines of code are not executed, which may lead to unexpected results.
Instead of
Code:try {
text(words.get("rightUp").toString(), width/2+10,10);
text(words.get("rightDown").toString(), width/2+10,height/2+10);
text(words.get("leftUp").toString(), 10,10);
text(words.get("leftDown").toString(), 10,height/2+10);
text(restant,5,height/2-40);
} catch (NullPointerException e) {}
I would use a helper function to test if the value is null
Code: text(getNum("rightUp"), width/2+10,10);
text(getNum("rightDown"), width/2+10,height/2+10);
text(getNum("leftUp"), 10,10);
text(getNum("leftDown"), 10,height/2+10);
text(restant,5,height/2-40);
Code:String getNum(String w) {
Integer n = (Integer)words.get(w);
if (n == null)
return "0";
return n.toString();
}
The second thing is that you should probably initialize the String you are using for the results at the beginning of the printWords method to an empty String. It should look something like this:
Code:void printWords() {
restant = "";
Iterator iter = words.keySet().iterator();
while(iter.hasNext()){
name = iter.next().toString();
if (name.equals("rightUp") == false && name.equals("leftUp") == false && name.equals("rightDown") == false && name.equals("leftDown") == false) {
println(name + " " + words.get(name));
}
restant = restant + name + " " + words.get(name) + " ";
}
Hope this helps