//
// HitoriScore.java
// Copyright (c) 1997 by Hidetaka Manu- Masuda
// This program is for viewing HitoriPoker ranking.
// Non-Commercial use only.
// 

import java.io.*;
import java.net.*;
import java.awt.*;
import java.util.*;
import java.awt.image.*;
import java.applet.Applet;

public class HitoriScore extends Applet implements Runnable {

TextArea txt1, txt2;
Label lbl1;
Panel pnl1;
Font aFont;

Button b = new Button("Update Scores");

public void init() {
	setBackground(Color.white);
	aFont = new Font("Helvetica", Font.BOLD, 12); 
	setLayout(new BorderLayout());
	lbl1 = new Label("HitoriPoker Ver.1.0 Copyright (c) 1997 by Manu-, Original 1993 by K.Tsuji", 
		Label.CENTER);
	lbl1.setFont(aFont);
	add("North", lbl1);
	txt1 = new TextArea("", 20, 50);
	txt1.setEditable(false);
	add("Center", txt1);
	txt2 = new TextArea("", 15, 20);
	txt2.setEditable(false);
	loadRoles();
	add("East", txt2);
	pnl1 = new Panel();
	pnl1.setLayout(new FlowLayout(FlowLayout.CENTER));
	pnl1.add(b);
	add("South", pnl1);
	getScore();
}

void loadRoles() {
	int i;
	String roleString;
	PokerRole aRole;
	txt2.setText("");
	txt2.appendText(" Poker Roles\n");
	txt2.appendText(" --------------\n");
	aRole = new PokerRole();
	for(i=9; i>=0; i--) {
		aRole.setRole(i);
		roleString = aRole.getRoleName() + "             ";
		roleString = roleString.substring(0, 10) + " " + aRole.printPoint();
		txt2.appendText(" "+roleString+"\n");
	}
}

public boolean action(Event e, Object o) {
	if(e.target instanceof Button) {
		getScore();
	}
	return true;
}

void getScore() {
	Thread getFile = new Thread(this);
	getFile.start();
}

public void run() {
	int i, range;
	range = 20;
	txt1.setText("");
	try {
        	URL url = new URL(getDocumentBase(), "p_best.dat");
                DataInputStream in = new DataInputStream(url.openStream());
                String s, numStr;
		for (i=0; i<range; i++) {
			s = in.readLine();
			numStr = ("   "+(i+1));
			txt1.appendText(numStr.substring(numStr.length()-3, numStr.length()));
			txt1.appendText(" "+s+"\n");
		}
                in.close();
	} catch(MalformedURLException e) {
		System.out.println("MalformedURLException!!");
        } catch(IOException e) {
		System.out.println("Read IOException!!");
        }
}

}