UrlText2 Applet

Note this is an applet with the old event handler system.

Download
© Comweb.nl , RJHM van den Bergh , sales@comweb.nl


File 1 of 1: UrlText2.java (Source code)
//
// URL TEXT 2
// RJHM van den Bergh
// All right reserved
// rvdb@nedernet.nl , rvdb@comweb.nl
//

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

public class UrlText2 extends Applet implements Runnable
{
    Thread runner,runner2;
    int delay=50, showTime=2000 , steps=50 ,currentStep=0, add=1;
    Color bgColor=Color.black,textColor=Color.white;
    Font font;
    String text[],statusBar[],barNow="";
    int x[],y[],currentLine;
    URL url[]; String target[];
    Image offScreenI;
    AudioClip sound;
    boolean mouseIn=false;
    Graphics offScreenG;
    Object frame;

public void init()
{
    System.out.println(getAppletInfo());

    delay=getNumber("delay",delay);
    steps=getNumber("steps",steps);
    showTime=getNumber("showtime",showTime);
    bgColor=getColor("bgcolor",bgColor);
    textColor=getColor("textcolor",textColor);
    font=getTheFont("font",getFont());
    if (getParameter("sound")!=null) sound=getAudioClip(getCodeBase(),getParameter("sound")) ; else sound=null;

    int n=0;
    while (getParameter("text_line_"+(n+1))!=null) n++;
    text=new String[n];
    x=new int[n];y=new int[n];
    url=new URL[n];
    target=new String[n];
    statusBar = new String[n];
    FontMetrics fm=getFontMetrics(font);
    for (int i=0;i=steps)
        {
            add=-1;
            pause(showTime);
        }

        if (currentStep==0)
        {
            add=+1;
            currentLine++;
            if (currentLine>=text.length)
            {
                currentLine=0;
            }
        }
    }

    while (Thread.currentThread()==runner2)
    {
        Thread.yield();
        pause(delay);
        if (mouseIn)
        {
            if (!barNow.equals(statusBar[currentLine]))
            {
                getAppletContext().showStatus(statusBar[currentLine]);
                barNow=statusBar[currentLine];
            }

            if ( url[currentLine]!=null)
            {
                if ( ((Frame)frame).getCursorType()!=Frame.HAND_CURSOR ) ((Frame)frame).setCursor(Frame.HAND_CURSOR);
            } else
            {
                if ( ((Frame)frame).getCursorType()!=Frame.DEFAULT_CURSOR) ((Frame)frame).setCursor(Frame.DEFAULT_CURSOR);
            }
        }
    }
}


private Font getTheFont(String parameter,Font font)
{
    String param=getParameter( parameter);
    if (param==null) return font;
    StringTokenizer tk=new StringTokenizer(param,"|,");
    if (tk.countTokens()!=3) return font;
    String[] token=new String[3];
    for (int i=0;i<3;i++) token[i]=tk.nextToken();
    try
    {
        int style=0;
        token[1]=token[1].toLowerCase().trim();
        if (token[1].equals("1") || token[1].indexOf("bold")!=-1) style++;
        if (token[1].equals("2") || token[1].equals("3") || token[1].indexOf("italic")!=-1) style=style+2;
        int size=Integer.parseInt(token[2]);
        return new Font(token[0],style,size);
    } catch (Exception e)
    {
        System.out.println("Couldn't get font out of \""+parameter);
        return font;
    }


}

private Color getColor(String parameter, Color defaultColor)
{
    String param=getParameter( parameter);
    if (param==null) return defaultColor;
    try
    {
        if (param.startsWith("#"))
        {
            return new Color(Integer.parseInt(param.substring(1,param.length()),16));
        } else
        {
            return new Color(Integer.parseInt(param));
        }
    } catch (NumberFormatException e)
    {
        System.out.println("Parameter \""+parameter+"\" isn't a number or RGB value.");
        return defaultColor;
    }
}

private int getNumber(String parameter, int defaultValue)
{
    String param=getParameter(parameter);
    if (param==null) return defaultValue;
    try
    {
        if (param.startsWith("#"))
        {
            return Integer.parseInt(param.substring(1,param.length()),16);
        } else
        {
            return Integer.parseInt(param);
        }
    } catch (NumberFormatException e)
    {
        System.out.println("Parameter \""+parameter+"\" isn't a number");
        return defaultValue;
    }
}

public String getAppletInfo()
{
    return " \n \nUrl Text 2.x \nAll Rights Reserved\nRJHM van den Bergh \nrvdb@nedernet.nl or rvdb@comweb.nl \n \n";
}

public void pause(int time)
{
    if (time==0) return;
    int sleep=0;
    if (time>1000)
    {
        time-=1000;
        sleep=1000;
    } else
    {
        sleep=time;
        time=0;
    }
    try
    {
        Thread.sleep(sleep);
    } catch (InterruptedException e){}
    if (sleep>1000) repaint();
    if (time==0) return;
    pause(time);
}


}