
import java.applet.*;
import java.io.*;
import java.awt.*;
import java.net.*;
import java.util.Random;

public class Counter extends Applet
{	public void init()
	{	int countVal = 0;
		String filename = "count.txt";	
		setBackground(Color.white);	
		Random ran = new Random();
		try
		
		{	int port = Integer.parseInt(getParameter("port"));
			String file = getParameter("file");
			if(file != null) filename = file;
			URL base = getDocumentBase();
			String all = base.toString();
			String dir = all.substring(0, all.lastIndexOf('/') );
			URL countfile = new URL(dir +'/'+ filename);
	//	System.out.println(countfile);
			Socket connection = new Socket( base.getHost(),port);
			BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream());
			out.writeObject(countfile);
			out.flush();
			countVal = Integer.parseInt(in.readLine());
			in.close();
		}
		catch(Exception e)
		{ 
		}
		Label countLabel = new Label(prefix[Math.abs(ran.nextInt()) % prefix.length] + countVal +" times.");
		countLabel.setBackground(Color.white);
		add(countLabel);
	}
	
	
	private static String [] prefix = 
	{	"This page has been visited billions and billions and ",
		"This page has been visited ",
		"People have been here about ",
		"I think you've been here about ",
		"This page has been visited millions and billions and ",
		"This page has been visited billions and trillions and ",
		"Someone has been here no less than ",
		"Various netizens have wandered through here about "
		
	};
}
