// This is, hey hey, jim nevel, from bellmont.
//	blab program Kava 7-9-01
// JN v 3 (post JNConsole testing/stabalization)
// ---------------------------------------------
// open file
// read list of lines
// choose random one
// display it
// -------------------- 7.10.01
// try adding repaint() to init.
// nope, let's try start()...
// -------------------- 7 17 01
// Gonna try to fix it!!!

// applet face imports
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
// baseline imports
import java.lang.Math;
import java.io.*;

class JNCa extends Applet {
	public void paint(Graphics g) {
		g.setColor(Color.red);
		g.drawString(toString(), 2, 17);
	}
	public  void init() {
		fileName = new String("prose");
		try {
			phraseFile = new LineNumberReader(new FileReader(fileName));
		} catch (FileNotFoundException e) { 
			System.out.println("OpenFile: ERROR: "+fileName);
		}
		try {
		try {
			numPhrases = Integer.parseInt(phraseFile.readLine());
			System.out.println("numPhrases: "+numPhrases);
		} catch (IOException e) { System.out.println("IOEx"); }
		} catch (NumberFormatException n) { System.out.println("NFEx"); }
		try {
			phraseFile.mark(32000);
		} catch (IOException e) { System.out.println("Mark fail");}
	}

	public 	String toString() {
		getPhrase();
		return phrase;
	}

	private void getPhrase() {
		System.out.print ("getPhrase(");
		int lineNumber = 1+(int)((double)numPhrases*Math.random());
		System.out.println (lineNumber+"):");
		phrase = readLine(lineNumber);
	}

	private String readLine(int lineNo) {
		String s = new String();
		try {
			for (int i=1; i<lineNo; i++) phraseFile.readLine();
			s = phraseFile.readLine();
			phraseFile.reset();
		} catch (IOException e) { System.out.println("IOEx"); }
		return s;
	}

	public void start() {
		setBackground(Color.black);
		repaint();
 	}

	private LineNumberReader phraseFile;
	private int numPhrases = 0;
	private String fileName;
	private String phrase;
}
