"List<String> words = new ArrayList<String>();" do not compiles
<p>I've posted a question on how to read from a file and return a random word from that file, and everyone keeps telling me use "List words = new ArrayList();" I did try to use it and it doesnt work!</p>

<p>I've tried everything! i'm very new at java, for i'm still a student! so the internet is my last option, text books are useless...</p>

<p>all i want to do is return a random string from that file and then use it as the guessing word</p>

<p><img src="http://i.stack.imgur.com/fbipb.png" alt="enter image description here">
</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Random;
import java.util.*;

public final class Hangman extends JFrame implements ActionListener {
    int i = 0;
    static JPanel panel;
    static JPanel panel2;
    static JPanel panel3;
    static JPanel panel4;

    public Hangman() {
        JButton[] buttons = new JButton[26];

        panel = new JPanel(new GridLayout(0, 9));
        panel2 = new JPanel();
        panel3 = new JPanel();
        panel4 = new JPanel();

        JButton btnRestart = new JButton("Restart");
        btnRestart.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

            }
        });

        JButton btnNewWord = new JButton("Add New Word");
        btnNewWord.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    FileWriter fw = new FileWriter("Words.txt", true);
                    PrintWriter pw = new PrintWriter(fw, true);

                    String word = JOptionPane
                            .showInputDialog("Please enter a word: ");

                    pw.println(word);
                    pw.close();
                } catch (IOException ie) {
                    System.out.println("Error Thrown" + ie.getMessage());
                }
            }
        });

        JButton btnHelp = new JButton("Help");
        btnHelp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String message = "The word to guess is represented by a row of dashes, giving the number of letters and category of the word. \nIf the guessing player suggests a letter which occurs in the word, the other player writes it in all its correct positions. \nIf the suggested letter does not occur in the word, the other player draws one element of the hangman diagram as a tally mark."
                        + "\n"
                        + "\nThe game is over when:"
                        + "\nThe guessing player completes the word, or guesses the whole word correctly"
                        + "\nThe other player completes the diagram";
                JOptionPane.showMessageDialog(null, message, "Help",
                        JOptionPane.INFORMATION_MESSAGE);
            }
        });

        JButton btnExit = new JButton("Exit");
        btnExit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        JLabel lblWord = new JLabel();

        ImageIcon icon = new ImageIcon(
                "D:\\Varsity College\\Prog212Assign1_10-013803\\images\\Hangman1.jpg");
        JLabel label = new JLabel();
        label.setIcon(icon);
        String b[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
                "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
                "X", "Y", "Z" };
        for (i = 0; i &lt; buttons.length; i++) {
            buttons[i] = new JButton(b[i]);

            panel.add(buttons[i]);
        }

        panel2.add(label);

        panel3.add(btnRestart);
        panel3.add(btnNewWord);
        panel3.add(btnHelp);
        panel3.add(btnExit);

        panel4.add(lblWord);
    }

    public void readWord() {
        try {
            BufferedReader reader = new BufferedReader(new FileReader(
                    "Words.txt"));
            String line = reader.readLine();
            List&lt;String&gt; words = new ArrayList&lt;String&gt;();
            while (line != null) {
                String[] wordsLine = line.split(" ");
                for (String word : wordsLine) {
                    words.add(word);
                }
                line = reader.readLine();
            }
            Random rand = new Random(System.currentTimeMillis());
            String randomWord = words.get(rand.nextInt(words.size()));
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        Hangman frame = new Hangman();
        Box mainPanel = Box.createVerticalBox();
        frame.setContentPane(mainPanel);
        mainPanel.add(panel, BorderLayout.NORTH);
        mainPanel.add(panel2);
        mainPanel.add(panel4);
        mainPanel.add(panel3);
        frame.pack();
        frame.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
</code></pre>
