// ©1998 Sebastian Wallroth

import java.applet.*;
import java.awt.*;
import java.net.*;

public class radar extends Applet implements Runnable 
{

	private Thread Animation = null;
	private Image Buffer;
	private Graphics gBuffer;
	int appletWidth, appletHeight, w, w1, i,  backR, backG, backB, delay, xx, yy;
	boolean vert, klick;
	String address;
	int l[] = new int[6];
	int stringX[] = new int[6];
	int stringY[] = new int[6];
	int fontSize[] = new int[6];
	int stringWidth[] = new int[6];
	String target[] = new String[6];
	String string[] = new String[6];
	Color color[] = new Color[51];
	Color c[] = new Color[6];
	URL url[] = new URL[6];
	Font font[] = new Font[6];
	
	public void start() 
	{
		if (Animation==null) 
		{
			Animation = new Thread (this);
			Animation.start();
		}
	}

	public void stop() 
	{
		if (Animation != null) 
		{
			Animation.stop();
			Animation=null;
		}
	}

	public void run() 
	{
		while (true) 
		{
			repaint();
			try 
			{
				Thread.sleep (delay);
			} catch (Exception e) {}
		}
	}

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

// Reading integer parameters
	private String getStringParam(String name, String standartWert) 
	{
		String param=getParameter(name);
		if (param==null) return standartWert;
		return param;
	}

// Reading String parameters
	private int getIntParam(String name, int standartWert) 
	{
		String param=getParameter(name);
		if (param==null) return standartWert;
		return (Integer.parseInt(param,10));
	}

	public void init() 
	{
		Buffer=createImage(size().width,size().height);
		gBuffer=Buffer.getGraphics();
// Height and width of the applet
		appletWidth = size().width;
		appletHeight = size().height;
// Delay of animation
		delay = getIntParam("delay",10);
		w=91;
// Getting parameters and setting standard values
		string[1] = getStringParam("string1","Herzlich Willkommen!");
		stringWidth[1] = getIntParam("stringWidth1",105);
		stringX[1] = getIntParam("stringX1",50);
		stringY[1] = getIntParam("stringY1",50);
		fontSize[1] = getIntParam("fontSize1",10);

		string[2] = getStringParam("string2","Welcome!");
		stringWidth[2] = getIntParam("stringWidth2",55);
		stringX[2] = getIntParam("stringX2",130);
		stringY[2] = getIntParam("stringY2",70);
		fontSize[2] = getIntParam("fontSize2",12);

		string[3] = getStringParam("string3","Accueil!");
		stringWidth[3] = getIntParam("stringWidth3",60);
		stringX[3] = getIntParam("stringX3",20);
		stringY[3] = getIntParam("stringY3",90);
		fontSize[3] = getIntParam("fontSize3",18);

		string[4] = getStringParam("string4","");
		stringWidth[4] = getIntParam("stringWidth4",120);
		stringX[4] = getIntParam("stringX4",50);
		stringY[4] = getIntParam("stringY4",150);
		fontSize[4] = getIntParam("fontSize4",12);

		string[5] = getStringParam("string5","Thanx to Sebastian Wallroth");
		stringWidth[5] = getIntParam("stringWidth5",100);
		stringX[5] = getIntParam("stringX5",60);
		stringY[5] = getIntParam("stringY5",170);
		fontSize[5] = getIntParam("fontSize5",8);

		backR = getIntParam("R",0);
		backG = getIntParam("G",0);
		backB = getIntParam("B",0);

		font[1] = new Font(getStringParam("Schriftart1","Helvetica"),Font.PLAIN,fontSize[1]);
		font[2] = new Font(getStringParam("Schriftart2","Courier"),Font.PLAIN,fontSize[2]);
		font[3] = new Font(getStringParam("Schriftart3","TimesRoman"),Font.PLAIN,fontSize[3]);
		font[4] = new Font(getStringParam("Schriftart4","Dialog"),Font.PLAIN,fontSize[4]);
		font[5] = new Font(getStringParam("Schriftart5","Helvetica"),Font.PLAIN,fontSize[5]);
//
// Address of the HTML-page, calling the class file
		String tempString = getDocumentBase().toExternalForm();
// Getting the folder
		String address = tempString.substring(0, tempString.lastIndexOf("/")+1);
//
		try {url[1]=new URL(getStringParam("url1",address+"deutsch/index.html"));}
		catch(MalformedURLException mal){}
		try {url[2]=new URL(getStringParam("url2",address+"english/index.html"));}
		catch(MalformedURLException mal){}
		try {url[3]=new URL(getStringParam("url3",address+"francais/index.html"));}
		catch(MalformedURLException mal){}
		try {url[4]=new URL(getStringParam("url4",address+"polska/index.html"));}
		catch(MalformedURLException mal){}
		try {url[5]=new URL(getStringParam("url5","http://www.wallroth.de/java/radar/"));}
		catch(MalformedURLException mal){}
		
		for(int i=1;i<6;i++) 
		{
// If url doesn't start with http:, file:, ftp, or mailto:,
// folder 'address' is preadded to the url
			if (url[i].toExternalForm().startsWith("http:")||url[i].toExternalForm().startsWith("file:")||url[i].toExternalForm().startsWith("ftp:")||url[i].toExternalForm().startsWith("mailto:")) {} 
			else try {url[i]=new URL(address+url[1].toExternalForm());}
			catch(MalformedURLException mal){}
// 
			target[i]=getStringParam("target"+Integer.toString(i),"_top");
		}
// Rectangular background shape
		gBuffer.setColor(new Color(backR,backG,backB));
		gBuffer.fillRect(0, 0, size().width, size().height);
// Circular background shape
		gBuffer.setColor(Color.black);
		gBuffer.fillOval(0, 0, size().width, size().height);
// Link color
		c[1] = c[2] = c[3] = c[4] = c[5] = Color.black;
// Creating 50 differential colors
		for(int i=1;i<51;i++) 
		{
			int j = i*5;
			color[i] = new Color(0,250-j,0);
		}
//
	}

	public boolean mouseMove(Event evt,int x,int y)
	{
		xx=x;
		yy=y;			
		repaint();
		return true;
	}				

	public boolean mouseDown(Event evt,int x,int y)
	{
		klick=true;
		l[1]=l[2]=l[3]=l[4]=l[5]=0;
		repaint();				
		return true;
	}

	public boolean mouseUp(Event evt,int x,int y)
	{
		klick=false;
		for(int i=1;i<6;i++) 
		{
			if(l[i]==1)getAppletContext().showDocument(url[i],target[i]);
		}
		repaint();			
		return true;			
	}	

	

	public void paint(Graphics g) 
	{
		for(int i=1;i<6;i++) 
		{
			if (xx>stringX[i]&&xx<stringX[i]+stringWidth[i]&&yy>stringY[i]-fontSize[i]&&yy<stringY[i])
			{	
				c[i] = Color.green;
				l[i]=1;
			}
			else c[i] = Color.black;
			gBuffer.setColor(c[i]);
			gBuffer.setFont(font[i]);
			gBuffer.drawString(string[i], stringX[i], stringY[i]);
		}
		g.drawImage (Buffer,0,0,this);
		w--;
		if (w==0) w=360;
		for(int i=1;i<51;i++)
		{		
			gBuffer.setColor(color[i]);
			gBuffer.fillArc(0, 0, appletWidth, appletHeight, w+i*5, 5);
		}
	}
}
