// 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:   HighScoreTable.java

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.Arrays;
import javax.swing.*;

public class HighScoreTable extends JFrame
    implements ActionListener
{

    HighScoreTable(String s)
        throws IOException
    {
        setTitle(s);
        initTable();
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        dispose();
    }

    public synchronized void addScore(Score score)
    {
        if(score.getScore() > scoreTable[0].getScore())
        {
            getContentPane().remove(scoreTable[0]);
            scoreTable[0] = score;
            getContentPane().add(score);
            score.setBackground(Color.lightGray);
            score.setFont(new Font("SansSerif", 1, 25));
            Arrays.sort(scoreTable, score);
            for(int i = 0; i < 10; i++)
                scoreTable[i].reshape(0, 5 + (9 - i) * 20, getWidth(), 20);

        }
    }

    private void initTable()
        throws IOException
    {
        scoreTable = new Score[10];
        getContentPane().setLayout(null);
        setResizable(false);
        setSize(new Dimension(150, 270));
        button = new JButton("Ok");
        getContentPane().add(button);
        button.reshape(getWidth() / 2 - 40, getHeight() - 60, 80, 30);
        button.addActionListener(this);
        for(int i = 0; i < 10; i++)
        {
            scoreTable[i] = new Score((i + 1) * 2);
            getContentPane().add(scoreTable[i]);
            scoreTable[i].setBackground(Color.lightGray);
            scoreTable[i].reshape(0, 5 + (9 - i) * 20, getWidth(), 20);
            scoreTable[i].setFont(new Font("SansSerif", 1, 25));
        }

    }

    public static void main(String args[])
        throws IOException
    {
        InputStreamReader inputstreamreader = new InputStreamReader(System.in);
        BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
        HighScoreTable highscoretable = new HighScoreTable("Test table");
        do
        {
            System.out.println();
            System.out.println("Current score table:");
            System.out.println(highscoretable);
            highscoretable.setDefaultCloseOperation(2);
            highscoretable.show();
            Player player = new Player(highscoretable);
            System.out.print("Enter a score:");
            Score score = new Score((new Integer(bufferedreader.readLine())).intValue());
            score.setPlayer(player);
            highscoretable.addScore(score);
        } while(true);
    }

    public String toString()
    {
        String s = new String();
        s = s + getTitle() + "\n";
        for(int i = 9; i >= 0; i--)
            s = s + scoreTable[i] + "\n";

        return s;
    }

    Score scoreTable[];
    JButton button;
}

