package com.nigorojr.typebest;

import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class Word extends JPanel implements Iterator<Letter> {
    private ArrayList<Letter> letters = new ArrayList<Letter>();
    private Iterator<Letter> lettersIterator;
    private String rawWord;

    /**
     * Accepts a String which is what will be shown in this JPanel.
     * The constructor will then split the word into letters and create a Letter
     * object for each letter. After that, Letter objects are added to the
     * this JPanel.
     * 
     * @param word
     *            The word that will be shown as a collection of "Letter" class.
     * @param pref
     *            A Preferences object that contains information such as the
     *            foreground color, background color and the font of the
     *            letters.
     */
    public Word(String word, Preferences pref) {
        rawWord = word;

        split(word);
        setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
        for (int i = 0; i < letters.size(); i++)
            this.add(letters.get(i));

        lettersIterator = letters.iterator();
    }

    /**
     * Splits up the word into letters and add them to an ArrayList.
     * 
     * @param word
     *            The word represented by this class.
     */
    private void split(String word) {
        for (int i = 0; i < rawWord.length(); i++) {
            Letter letter = new Letter(rawWord.charAt(i));
            letters.add(letter);
        }
    }

    /**
     * Returns the next letter. This method can be used to avoid confusion when
     * using the <code>next</code> method in the Line class.
     * 
     * @return The next letter as a Letter object.
     */
    public Letter nextLetter() {
        return next();
    }

    @Override
    public boolean hasNext() {
        return lettersIterator.hasNext();
    }

    @Override
    public Letter next() {
        return lettersIterator.next();
    }

    @Override
    public void remove() {
        lettersIterator.remove();
    }
}

@@ -1010,89 +1010,8 @@
 d;%0A%0A
-        split(word);%0A        setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));%0A
     
@@ -1038,28 +1038,30 @@
 i %3C 
-letters.size
+rawWord.length
 (); i++)
 %0A   
@@ -1056,16 +1056,18 @@
 (); i++)
+ %7B
 %0A       
@@ -1075,291 +1075,164 @@
     
-this.add(letters.get(i));%0A%0A        lettersIterator = letters.iterator(
+Letter letter = new Letter(rawWord.charAt(i), pref
 );%0A    
-%7D%0A%0A
     
-/**%0A     * Splits up the word into letters and add them to an ArrayList.%0A     * %0A     * @param word%0A     *            The word represented by this class.%0A     */%0A    private void split(String word) %7B
+    letters.add(letter);%0A        %7D%0A%0A        setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
 %0A   
@@ -1256,38 +1256,36 @@
  0; i %3C 
-rawWord.length
+letters.size
 (); i++)
  %7B%0A     
@@ -1268,34 +1268,32 @@
 ers.size(); i++)
- %7B
 %0A            Let
@@ -1293,59 +1293,35 @@
     
-Letter letter = new Letter(rawWord.charA
+this.add(letters.ge
 t(i));%0A
-    
+%0A
     
@@ -1331,39 +1331,46 @@
  letters
-.add(letter);%0A        %7D
+Iterator = letters.iterator();
 %0A    %7D%0A%0A

Delete split() method in Word class