// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   BoggleGUI.java

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.EventObject;

public class BoggleGUI extends Applet
    implements ActionListener, WindowListener, Runnable
{

    public BoggleGUI()
    {
        scoreFont = new Font("Arial", 1, 36);
        standardFont = new Font("Helvetica", 1, 14);
        standardFontPlain = new Font("Helvetica", 0, 18);
        standardFontLarge = new Font("Helvetica", 1, 18);
        standardFontHuge = new Font("Helvetica", 1, 72);
        infoFont = new Font("Tahoma", 1, 20);
        infoFontLarge = new Font("Tahoma", 0, 22);
        buttonFont = new Font("Arial", 0, 16);
        statsWindow = new Frame("Your Totals");
        bgColor = new Color(153, 153, 153);
        bufferColor = new Color(150, 150, 150);
        updateLabels = true;
        createEffect = 0;
        gameOn = 0;
        st = 0;
        word = "";
        usedWords = new String[500];
        totalUsedWords = 0;
        gameTime = 0;
        requestAddWord = false;
        newWordAdded = false;
        addMode = false;
        commandEdition = false;
        minWordSize = 4;
        boardSize = 5;
        colours = new int[boardSize * boardSize + 1];
        board = new Label[boardSize * boardSize + 1];
        FADE_EFFECT_DIFF = 4;
        FADE_EFFECT_CONSTANT = (int)Math.pow(boardSize - 1, 2D);
        testString = new String[10];
        testLabel = new Label[10];
    }

    public void init()
    {
        BOX_SIZE = 300 / boardSize;
        boggle = new Boggle(minWordSize, boardSize);
        bufferImg = createImage(800, 600);
        buffer = bufferImg.getGraphics();
        String s = "Words you Missed\n----------------------------------------\n";
        testArea = new TextArea(s, 8, 30, 1);
        testArea.setBackground(new Color(0, 0, 150));
        testArea.setForeground(Color.white);
        testArea.setFont(standardFont);
        for(n = 0; n <= 7; n++)
            testLabel[n] = new Label("");

        setLoc();
        for(n = 0; n <= 7; n++)
            statsWindow.add(testLabel[n]);

        statsWindow.setSize(400, 450);
        statsWindow.setLocation(200, 80);
        statsWindow.add(testArea);
        startButton = new Button("Start");
        startButton.setFont(buttonFont);
        startButton.addActionListener(this);
        startButton.setActionCommand("start/stop");
        restartButton = new Button("Restart");
        restartButton.setFont(buttonFont);
        restartButton.addActionListener(this);
        restartButton.setActionCommand("restart");
        restartButton.setEnabled(false);
        wordBox = new TextField(20);
        wordBox.setFont(standardFont);
        wordBox.addActionListener(this);
        add(startButton);
        add(restartButton);
        add(wordBox);
        for(n = 1; n <= boardSize * boardSize; n++)
        {
            board[n] = new Label("", 1);
            board[n].setFont(new Font("Verdana", 1, BOX_SIZE - 12));
            board[n].setForeground(new Color(220, 220, 220));
            board[n].setBackground(new Color(0, 0, 0));
            add(board[n]);
            colours[n] = 0;
        }

        infoLabel = new Label("Welcome to Boggle!", 0);
        infoLabel.setFont(infoFont);
        infoLabel.setForeground(new Color(154, 255, 136));
        scoreLabel = new Label("Score: 0", 0);
        scoreLabel.setFont(scoreFont);
        scoreLabel.setForeground(new Color(0, 0, 255));
        remainingLabel = new Label("Welcome to Boggle!", 0);
        remainingLabel.setFont(infoFontLarge);
        remainingLabel.setForeground(new Color(255, 255, 0));
        if(addMode)
        {
            startButton.setEnabled(false);
            restartButton.setEnabled(false);
            infoLabel.setText("WARNING - ADD MODE ENGAGED!");
            remainingLabel.setText("WARNING - ADD MODE ENGAGED!");
        }
        dictLabel = new Label("Dictionary Words: ", 2);
        dictLabel.setFont(standardFontPlain);
        dictLabel.setForeground(new Color(130, 0, 255));
        dictLabel.setBackground(bgColor);
        words1Label = new Label("Your Words Found", 1);
        words1Label.setFont(standardFontLarge);
        words1Label.setForeground(new Color(0, 255, 0));
        myWords1Label = new Label("My Words Found", 1);
        myWords1Label.setFont(standardFontLarge);
        myWords1Label.setForeground(new Color(0, 255, 255));
        words2Label = new Label("Your Word Total", 1);
        words2Label.setFont(standardFontLarge);
        words2Label.setForeground(new Color(0, 215, 162));
        myWords2Label = new Label("My Word Total", 1);
        myWords2Label.setFont(standardFontLarge);
        myWords2Label.setForeground(new Color(0, 182, 242));
        totalLabel = new Label("0", 1);
        totalLabel.setFont(standardFontHuge);
        totalLabel.setForeground(new Color(0, 255, 190));
        myTotalLabel = new Label("0", 1);
        myTotalLabel.setFont(standardFontHuge);
        myTotalLabel.setForeground(new Color(70, 209, 255));
        words4Label = new Label(minWordSize + " Letter Words: 0", 0);
        words4Label.setFont(standardFont);
        words4Label.setForeground(new Color(0, 200, 0));
        words5Label = new Label((minWordSize + 1) + " Letter Words: 0", 0);
        words5Label.setFont(standardFont);
        words5Label.setForeground(new Color(0, 218, 0));
        words6Label = new Label((minWordSize + 2) + " Letter Words: 0", 0);
        words6Label.setFont(standardFont);
        words6Label.setForeground(new Color(0, 236, 0));
        words7Label = new Label((minWordSize + 3) + "+ Letter Words: 0", 0);
        words7Label.setFont(standardFont);
        words7Label.setForeground(new Color(0, 255, 0));
        myWords4Label = new Label(minWordSize + " Letter Words: 0", 0);
        myWords4Label.setFont(standardFont);
        myWords4Label.setForeground(new Color(0, 200, 200));
        myWords5Label = new Label((minWordSize + 1) + " Letter Words: 0", 0);
        myWords5Label.setFont(standardFont);
        myWords5Label.setForeground(new Color(0, 218, 218));
        myWords6Label = new Label((minWordSize + 2) + " Letter Words: 0", 0);
        myWords6Label.setFont(standardFont);
        myWords6Label.setForeground(new Color(0, 236, 236));
        myWords7Label = new Label((minWordSize + 3) + "+ Letter Words: 0", 0);
        myWords7Label.setFont(standardFont);
        myWords7Label.setForeground(new Color(0, 255, 255));
        words4Label.setBackground(bgColor);
        words5Label.setBackground(bgColor);
        words6Label.setBackground(bgColor);
        words7Label.setBackground(bgColor);
        words1Label.setBackground(bgColor);
        words2Label.setBackground(bgColor);
        totalLabel.setBackground(bgColor);
        myWords4Label.setBackground(bgColor);
        myWords5Label.setBackground(bgColor);
        myWords6Label.setBackground(bgColor);
        myWords7Label.setBackground(bgColor);
        myWords1Label.setBackground(bgColor);
        myWords2Label.setBackground(bgColor);
        myTotalLabel.setBackground(bgColor);
        infoLabel.setBackground(bgColor);
        scoreLabel.setBackground(bgColor);
        remainingLabel.setBackground(bgColor);
        add(dictLabel);
        add(words4Label);
        add(words5Label);
        add(words6Label);
        add(words7Label);
        add(words1Label);
        add(words2Label);
        add(totalLabel);
        add(myWords4Label);
        add(myWords5Label);
        add(myWords6Label);
        add(myWords7Label);
        add(myWords1Label);
        add(myWords2Label);
        add(myTotalLabel);
        add(infoLabel);
        add(scoreLabel);
        add(remainingLabel);
    }

    public void update(Graphics g)
    {
        paint(g);
    }

    public void paint(Graphics g)
    {
        buffer.setColor(bufferColor);
        buffer.fillRect(0, 0, 800, 600);
        buffer.setColor(Color.black);
        buffer.drawRect(320, 220, 399, 25);
        buffer.setColor(new Color(255, 0, 0));
        buffer.fillRect(321, 221, (int)Math.ceil(0.0044222222222222224D * (double)gameTime), 24);
        statsWindow.addWindowListener(this);
        startButton.setSize(80, 25);
        startButton.setLocation(210, 325);
        restartButton.setSize(80, 25);
        restartButton.setLocation(210, 355);
        wordBox.setSize(wordBox.getPreferredSize());
        wordBox.setLocation(10, 325);
        for(n = 0; n <= boardSize - 1; n++)
            for(n2 = 0; n2 <= boardSize - 1; n2++)
            {
                board[n + 1 + n2 * boardSize].setSize(BOX_SIZE - 10, BOX_SIZE - 10);
                board[n + 1 + n2 * boardSize].setLocation(16 + n * BOX_SIZE, 15 + n2 * BOX_SIZE);
            }


        if(createEffect == 1)
        {
            for(st = 1; st <= mnn; st++)
            {
                colours[st] -= FADE_EFFECT_CONSTANT;
                if(colours[st] >= 0 && colours[st] <= 220)
                    board[st].setForeground(new Color(colours[st], colours[st], colours[st]));
                if(colours[st] <= 0)
                {
                    board[st].setForeground(Color.black);
                    mnn--;
                }
            }

            repaint();
            if(mnn <= 0)
            {
                for(st = 1; st <= boardSize * boardSize; st++)
                {
                    colours[st] = 0 - (st - 1) * FADE_EFFECT_DIFF;
                    board[st].setForeground(new Color(0, 0, 0));
                    board[st].setText(boggle.getBoard(st));
                }

                mnn = 1;
                boggle.findMyWords();
                if(boggle.getWordsToGo() == 1)
                    remainingLabel.setText("I found " + boggle.getWordsToGo() + " word.");
                else
                    remainingLabel.setText("I found " + boggle.getWordsToGo() + " words.");
                remainingLabel.setForeground(new Color(255, 255, 0));
                updateLabels = true;
                createEffect = 2;
            }
        } else
        if(createEffect == 2)
        {
            for(st = mnn; st <= boardSize * boardSize; st++)
            {
                colours[st] += FADE_EFFECT_CONSTANT;
                if(colours[st] >= 0 && colours[st] <= 220)
                    board[st].setForeground(new Color(colours[st], colours[st], colours[st]));
                if(colours[st] >= 220)
                {
                    mnn++;
                    board[st].setForeground(new Color(220, 220, 220));
                }
            }

            repaint();
            if(mnn > boardSize * boardSize)
            {
                createEffect = 0;
                startButton.setEnabled(true);
                restartButton.setEnabled(true);
                gameOn = 1;
                runner = new Thread(this);
                runner.start();
            }
        }
        if(updateLabels)
        {
            scoreLabel.setText("Score: " + boggle.getScore());
            words4Label.setText(minWordSize + " Letter Words: " + boggle.getWords4());
            words5Label.setText((minWordSize + 1) + " Letter Words: " + boggle.getWords5());
            words6Label.setText((minWordSize + 2) + " Letter Words: " + boggle.getWords6());
            words7Label.setText((minWordSize + 3) + "+ Letter Words: " + boggle.getWords7());
            myWords4Label.setText(minWordSize + " Letter Words: " + boggle.getMyWords4());
            myWords5Label.setText((minWordSize + 1) + " Letter Words: " + boggle.getMyWords5());
            myWords6Label.setText((minWordSize + 2) + " Letter Words: " + boggle.getMyWords6());
            myWords7Label.setText((minWordSize + 3) + "+ Letter Words: " + boggle.getMyWords7());
            totalLabel.setText("" + boggle.getTotal());
            myTotalLabel.setText("" + boggle.getMyTotal());
            updateLabels = false;
        }
        infoLabel.setSize(500, 40);
        infoLabel.setLocation(320, 10);
        scoreLabel.setSize(scoreLabel.getPreferredSize());
        scoreLabel.setLocation(10, 345);
        dictLabel.setText("Dictionary Words: " + boggle.dict.getTotalWords());
        dictLabel.setSize(250, 30);
        dictLabel.setLocation(500, 363);
        words1Label.setLocation(330, 60);
        words2Label.setSize(150, 30);
        words2Label.setLocation(540, 60);
        totalLabel.setSize(150, 80);
        totalLabel.setLocation(540, 90);
        remainingLabel.setSize(remainingLabel.getPreferredSize());
        remainingLabel.setLocation(320, 185);
        myWords1Label.setLocation(330, 250);
        myWords2Label.setSize(150, 30);
        myWords2Label.setLocation(540, 250);
        myTotalLabel.setSize(150, 80);
        myTotalLabel.setLocation(540, 280);
        words4Label.setSize(words4Label.getPreferredSize());
        words4Label.setLocation(353, 85);
        words5Label.setSize(words5Label.getPreferredSize());
        words5Label.setLocation(353, 105);
        words6Label.setSize(words6Label.getPreferredSize());
        words6Label.setLocation(353, 125);
        words7Label.setSize(words7Label.getPreferredSize());
        words7Label.setLocation(345, 145);
        myWords4Label.setSize(myWords4Label.getPreferredSize());
        myWords4Label.setLocation(353, 275);
        myWords5Label.setSize(myWords5Label.getPreferredSize());
        myWords5Label.setLocation(353, 295);
        myWords6Label.setSize(myWords6Label.getPreferredSize());
        myWords6Label.setLocation(353, 315);
        myWords7Label.setSize(myWords7Label.getPreferredSize());
        myWords7Label.setLocation(345, 335);
        buffer.setColor(new Color(0, 0, 0));
        buffer.fillRect(10, 10, (10 + BOX_SIZE * boardSize) - 10, (10 + BOX_SIZE * boardSize) - 10);
        for(n = 1; n <= boardSize - 1; n++)
        {
            buffer.setColor(new Color(200, 200, 200));
            buffer.drawLine(10 + BOX_SIZE * n, 10, 10 + BOX_SIZE * n, 10 + BOX_SIZE * boardSize);
            buffer.drawLine(10, 10 + BOX_SIZE * n, 10 + BOX_SIZE * boardSize, 10 + BOX_SIZE * n);
            buffer.setColor(new Color(160, 160, 160));
            buffer.drawLine(9 + BOX_SIZE * n, 10, 9 + BOX_SIZE * n, 10 + BOX_SIZE * boardSize);
            buffer.drawLine(11 + BOX_SIZE * n, 10, 11 + BOX_SIZE * n, 10 + BOX_SIZE * boardSize);
            buffer.drawLine(10, 9 + BOX_SIZE * n, 10 + BOX_SIZE * boardSize, 9 + BOX_SIZE * n);
            buffer.drawLine(10, 11 + BOX_SIZE * n, 10 + BOX_SIZE * boardSize, 11 + BOX_SIZE * n);
        }

        buffer.setColor(new Color(220, 220, 220));
        buffer.drawRect(10, 10, (10 + BOX_SIZE * boardSize) - 10, (10 + BOX_SIZE * boardSize) - 10);
        buffer.setColor(new Color(200, 200, 200));
        buffer.drawRect(9, 9, (10 + BOX_SIZE * boardSize) - 8, (10 + BOX_SIZE * boardSize) - 8);
        buffer.setColor(new Color(180, 180, 180));
        buffer.drawRect(8, 8, (10 + BOX_SIZE * boardSize) - 6, (10 + BOX_SIZE * boardSize) - 6);
        buffer.setColor(new Color(160, 160, 160));
        buffer.drawRect(7, 7, (10 + BOX_SIZE * boardSize) - 4, (10 + BOX_SIZE * boardSize) - 4);
        buffer.setColor(new Color(140, 140, 140));
        buffer.drawRect(6, 6, (10 + BOX_SIZE * boardSize) - 2, (10 + BOX_SIZE * boardSize) - 2);
        g.drawImage(bufferImg, 0, 0, this);
    }

    public void stop()
    {
        statsWindow.hide();
        gameOn = 0;
        runner = null;
        if(commandEdition && newWordAdded)
        {
            boggle.dict.saveFile();
            newWordAdded = false;
        }
    }

    public void endGame()
    {
        double d;
        requestAddWord = false;
        gameOn = 0;
        gameTime = 0x15f90;
        boolean flag = false;
        d = 0.0D;
        infoLabel.setText("");
        statsWindow.setLayout(new FlowLayout());
        if(boggle.getMyWords4() > 0)
            d = (((double)boggle.getMyWords4Found() - (double)boggle.getMyWords4()) / (double)boggle.getMyWords4Found()) * 100D;
        else
            d = 100D;
        d = Useful.roundTo(d, 2);
        testString[0] = "% of " + minWordSize + " letter words found: ";
        new StringBuffer();
        testString;
        0;
        JVM INSTR dup2_x1 ;
        JVM INSTR aaload ;
        append();
        d;
        append();
        "%";
        append();
        toString();
        JVM INSTR aastore ;
        if(boggle.getMyWords5() > 0)
            d = (((double)boggle.getMyWords5Found() - (double)boggle.getMyWords5()) / (double)boggle.getMyWords5Found()) * 100D;
        else
            d = 100D;
        d = Useful.roundTo(d, 2);
        testString[1] = "% of " + (minWordSize + 1) + " letter words found: ";
        new StringBuffer();
        testString;
        1;
        JVM INSTR dup2_x1 ;
        JVM INSTR aaload ;
        append();
        d;
        append();
        "%";
        append();
        toString();
        JVM INSTR aastore ;
        if(boggle.getMyWords6() > 0)
            d = (((double)boggle.getMyWords6Found() - (double)boggle.getMyWords6()) / (double)boggle.getMyWords6Found()) * 100D;
        else
            d = 100D;
        d = Useful.roundTo(d, 2);
        testString[2] = "% of " + (minWordSize + 2) + " letter words found: ";
        new StringBuffer();
        testString;
        2;
        JVM INSTR dup2_x1 ;
        JVM INSTR aaload ;
        append();
        d;
        append();
        "%";
        append();
        toString();
        JVM INSTR aastore ;
        if(boggle.getMyWords7() > 0)
            d = (((double)boggle.getMyWords7Found() - (double)boggle.getMyWords7()) / (double)boggle.getMyWords7Found()) * 100D;
        else
            d = 100D;
        d = Useful.roundTo(d, 2);
        testString[3] = "% of " + (minWordSize + 3) + "+ letter words found: ";
        new StringBuffer();
        testString;
        3;
        JVM INSTR dup2_x1 ;
        JVM INSTR aaload ;
        append();
        d;
        append();
        "%";
        append();
        toString();
        JVM INSTR aastore ;
        if(boggle.getMyTotal() > 0)
            d = (((double)boggle.getMyTotal() - (double)boggle.getWordsToGo()) / (double)boggle.getMyTotal()) * 100D;
        else
            d = 100D;
        d = Useful.roundTo(d, 2);
        testString[4] = "OVERALL % OF WORDS FOUND: ";
        new StringBuffer();
        testString;
        4;
        JVM INSTR dup2_x1 ;
        JVM INSTR aaload ;
        append();
        d;
        append();
        "%";
        append();
        toString();
        JVM INSTR aastore ;
        testString[5] = "OVERALL SCORE: " + boggle.getScore();
        testString[6] = "\"" + boggle.taunt(d) + "\"";
        testString[7] = "TIMES UP!";
        for(int i = 0; i <= 7; i++)
        {
            testLabel[i].setText(testString[i]);
            testLabel[i].setFont(standardFont);
        }

        for(int j = 0; j <= 3; j++)
            testLabel[j].setForeground(new Color(100 + j * 30, 0, 0));

        testLabel[4].setForeground(new Color(0, 255, 0));
        testLabel[4].setFont(standardFontLarge);
        testLabel[5].setForeground(new Color(0, 60, 255));
        testLabel[5].setFont(standardFontLarge);
        testLabel[6].setForeground(new Color(240, 240, 0));
        testLabel[7].setForeground(Color.white);
        testLabel[7].setFont(standardFontLarge);
        remainingLabel.setForeground(new Color(200, 0, 0));
        String s = "Words you Missed\n----------------------------------------\n";
        s = s + boggle.getMissedWords();
        testArea.setText(s);
        startButton.setLabel("Start");
        repaint();
        setLoc();
        statsWindow.show();
        setLoc();
        if(commandEdition && newWordAdded)
        {
            boggle.dict.saveFile();
            newWordAdded = false;
        }
        return;
    }

    public void setLoc()
    {
        testArea.setLocation(60, 230);
        testArea.setSize(testArea.getPreferredSize());
        boolean flag = false;
        testLabel[0].setSize(400, 15);
        testLabel[1].setSize(400, 15);
        testLabel[2].setSize(400, 15);
        testLabel[3].setSize(400, 15);
        testLabel[4].setSize(400, 15);
        testLabel[5].setSize(400, 30);
        testLabel[6].setSize(400, 30);
        testLabel[7].setSize(400, 30);
        testLabel[7].setLocation(10, 30);
        testLabel[0].setLocation(10, 60);
        testLabel[1].setLocation(10, 76);
        testLabel[2].setLocation(10, 92);
        testLabel[3].setLocation(10, 107);
        testLabel[4].setLocation(10, 135);
        testLabel[5].setLocation(10, 163);
        testLabel[6].setLocation(10, 190);
    }

    public void windowOpened(WindowEvent windowevent)
    {
    }

    public void windowClosing(WindowEvent windowevent)
    {
        statsWindow.hide();
    }

    public void windowClosed(WindowEvent windowevent)
    {
    }

    public void windowIconified(WindowEvent windowevent)
    {
    }

    public void windowDeiconified(WindowEvent windowevent)
    {
        setLoc();
    }

    public void windowActivated(WindowEvent windowevent)
    {
        setLoc();
    }

    public void windowDeactivated(WindowEvent windowevent)
    {
        setLoc();
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        if(actionevent.getSource() instanceof TextField)
        {
            if(addMode)
            {
                word = wordBox.getText().toUpperCase();
                wordBox.setText("");
                if(word.length() < minWordSize)
                {
                    infoLabel.setForeground(new Color(200, 0, 0));
                    infoLabel.setText("The word must be at least " + minWordSize + " letters long.");
                    repaint();
                    return;
                }
                if(boggle.dict.isWord(word))
                {
                    infoLabel.setForeground(new Color(200, 0, 0));
                    infoLabel.setText(word + " already exists.");
                } else
                {
                    boggle.dict.addWordInPlace(word);
                    infoLabel.setForeground(new Color(120, 250, 150));
                    infoLabel.setText(word + " added!");
                    newWordAdded = true;
                    updateLabels = true;
                    repaint();
                }
                return;
            }
            if(gameOn != 1)
            {
                infoLabel.setForeground(new Color(200, 0, 0));
                infoLabel.setText("The game hasn't begun yet!");
                return;
            }
            if(commandEdition && requestAddWord)
            {
                if(wordBox.getText().toUpperCase().equals("N") || wordBox.getText().toUpperCase().equals("NO"))
                {
                    infoLabel.setForeground(new Color(255, 179, 36));
                    infoLabel.setText("\"" + word + "\" is not found in the dictionary.");
                    wordBox.setText("");
                    updateLabels = true;
                    repaint();
                    requestAddWord = false;
                    return;
                }
                usedWords[totalUsedWords] = word;
                totalUsedWords++;
                boggle.dict.addWordInPlace(word);
                infoLabel.setForeground(new Color(70, 220, 70));
                if((word.length() - minWordSize) + 1 == 1)
                    infoLabel.setText(word + ": " + ((word.length() - minWordSize) + 1) + " point (just added)");
                else
                    infoLabel.setText(word + ": " + ((word.length() - minWordSize) + 1) + " points (just added)");
                newWordAdded = true;
                boggle.addPoints((word.length() - minWordSize) + 1);
                boggle.addWordCount(word.length());
                wordBox.setText("");
                requestAddWord = false;
                updateLabels = true;
                repaint();
                return;
            }
            word = wordBox.getText().toUpperCase();
            wordBox.setText("");
            if(word.length() < minWordSize)
            {
                infoLabel.setForeground(new Color(200, 0, 0));
                infoLabel.setText("The word must be at least " + minWordSize + " letters long.");
                repaint();
                return;
            }
            int i = boggle.findWord(word);
            if(i == 1)
            {
                for(n = 0; n < totalUsedWords; n++)
                    if(word.equals(usedWords[n]))
                    {
                        infoLabel.setText("\"" + word + "\" has already been used.");
                        infoLabel.setForeground(new Color(200, 50, 50));
                        return;
                    }

                usedWords[totalUsedWords] = word;
                totalUsedWords++;
                boggle.removeMyWord(word);
                boggle.addMyWordCount(word.length());
                if(boggle.getWordsToGo() == 1)
                    remainingLabel.setText(boggle.getWordsToGo() + " word to go.");
                else
                    remainingLabel.setText(boggle.getWordsToGo() + " words to go.");
                remainingLabel.setForeground(new Color(255, 255, 0));
                infoLabel.setForeground(new Color(0, 220, 0));
                if((word.length() - minWordSize) + 1 == 1)
                    infoLabel.setText(word + ": " + ((word.length() - minWordSize) + 1) + " point");
                else
                    infoLabel.setText(word + ": " + ((word.length() - minWordSize) + 1) + " points");
                boggle.addPoints((word.length() - minWordSize) + 1);
                boggle.addWordCount(word.length());
            } else
            if(i == 2)
            {
                if(commandEdition)
                {
                    infoLabel.setText("\"" + word + "\" not found in dicitonary.");
                    infoLabel.setForeground(new Color(170, 220, 220));
                    requestAddWord = true;
                } else
                {
                    infoLabel.setForeground(new Color(255, 179, 36));
                    infoLabel.setText("\"" + word + "\" is not found in the dictionary.");
                    return;
                }
            } else
            {
                infoLabel.setForeground(new Color(200, 0, 0));
                infoLabel.setText("\"" + word + "\" is not in the puzzle.");
            }
            updateLabels = true;
            repaint();
        } else
        if(actionevent.getActionCommand().equals("start/stop"))
        {
            if(startButton.getLabel().equals("Start"))
            {
                gameTime = 0;
                statsWindow.hide();
                startButton.setEnabled(false);
                startButton.setLabel("Stop");
                boggle.resetScores();
                boggle.createBoard();
                infoLabel.setText("");
                remainingLabel.setText("Searching...");
                remainingLabel.setForeground(new Color(170, 200, 170));
                if(board[n].getText().equals(""))
                {
                    mnn = 0;
                } else
                {
                    for(n = 1; n <= boardSize * boardSize; n++)
                        colours[n] = (255 + boardSize * boardSize * FADE_EFFECT_DIFF) - (n - 1) * FADE_EFFECT_DIFF;

                    mnn = boardSize * boardSize;
                }
                for(n = 0; n <= 499; n++)
                    usedWords[n] = "";

                totalUsedWords = 0;
                createEffect = 1;
                repaint();
            } else
            if(startButton.getLabel().equals("Stop"))
            {
                remainingLabel.setText("Stopped!");
                endGame();
            }
        } else
        if(actionevent.getActionCommand().equals("restart"))
        {
            statsWindow.hide();
            requestAddWord = false;
            infoLabel.setText("");
            restartButton.setEnabled(true);
            gameOn = 0;
            gameTime = 0;
            startButton.setEnabled(false);
            startButton.setLabel("Stop");
            boggle.resetScores();
            boggle.createBoard();
            infoLabel.setText("");
            remainingLabel.setText("Searching....");
            remainingLabel.setForeground(new Color(170, 200, 170));
            for(n = 1; n <= boardSize * boardSize; n++)
                colours[n] = (255 + boardSize * boardSize * FADE_EFFECT_DIFF) - (n - 1) * FADE_EFFECT_DIFF;

            for(n = 0; n <= 499; n++)
                usedWords[n] = "";

            totalUsedWords = 0;
            mnn = boardSize * boardSize;
            createEffect = 1;
            repaint();
        }
    }

    public void run()
    {
        while(gameOn == 1) 
        {
            try
            {
                Thread.sleep(100L);
            }
            catch(InterruptedException interruptedexception) { }
            gameTime += 100;
            if(gameTime >= 0x15f90)
            {
                remainingLabel.setText("TIME'S UP!");
                endGame();
            }
            repaint();
        }
        runner = null;
    }

    Font scoreFont;
    Font standardFont;
    Font standardFontPlain;
    Font standardFontLarge;
    Font standardFontHuge;
    Font infoFont;
    Font infoFontLarge;
    Font buttonFont;
    Boggle boggle;
    private int n;
    private int n2;
    Thread runner;
    Button startButton;
    Button restartButton;
    TextField wordBox;
    Label words4Label;
    Label words5Label;
    Label words6Label;
    Label words7Label;
    Label words1Label;
    Label words2Label;
    Label totalLabel;
    Label myWords4Label;
    Label myWords5Label;
    Label myWords6Label;
    Label myWords7Label;
    Label myWords1Label;
    Label myWords2Label;
    Label myTotalLabel;
    Label infoLabel;
    Label scoreLabel;
    Label remainingLabel;
    Label dictLabel;
    Frame statsWindow;
    private TextArea testArea;
    private Image bufferImg;
    private Graphics buffer;
    private Color bgColor;
    private Color bufferColor;
    private boolean updateLabels;
    private int createEffect;
    private int gameOn;
    private int st;
    private String word;
    private final int LETTER_COLOUR = 220;
    private final int GAME_LENGTH = 0x15f90;
    private final int TIMER_INTERVAL = 100;
    private String usedWords[];
    private int totalUsedWords;
    private int gameTime;
    private boolean requestAddWord;
    private int BOX_SIZE;
    int mnn;
    private boolean newWordAdded;
    private boolean addMode;
    private boolean commandEdition;
    private int minWordSize;
    private int boardSize;
    private int colours[];
    Label board[];
    private int FADE_EFFECT_DIFF;
    private int FADE_EFFECT_CONSTANT;
    String testString[];
    Label testLabel[];
}

