import java.awt.*;
import java.applet.Applet;
import java.applet.AppletContext;
import java.io.PrintStream;
import java.net.URL;

public class myScroll extends Applet implements Runnable
{
    Thread runner;
    String message;
    Font nf;
    Graphics offScreeng;
    Image img;
    int width;
    int height;
    int message_width;
    int X;
    int fontstyle;
    FontMetrics fmetrics;
    Color bgc;
    Color fgc;
    long hiz;
    int bgcolor;
    int fgcolor;

    public void init()
    {
        String string1 = "";
        String string2 = "";
        string1 = getParameter("bgcolor");
        try
        {
            bgcolor = Integer.parseInt(string1, 16);
        }

        catch (Exception e1)
        {
            bgcolor = 0;
        }

        bgc = new Color(bgcolor);
        setBackground(bgc);
        string2 = getParameter("fgcolor");
        try
        {
            fgcolor = Integer.parseInt(string2, 16);
        }
        catch (Exception e2)
        {
            fgcolor = 16777215;
        }

        try
        {
            fontstyle = Integer.parseInt(getParameter("fontstyle"), 10);
        }
        catch (Exception e3)
        {
            fontstyle = 0;
        }

        fgc = new Color(fgcolor);
        show();
        setForeground(fgc);
        message = getParameter("text");
        nf = new Font(getParameter("fonttype"), fontstyle, Integer.valueOf(getParameter("fontsize")).intValue());
        width = size().width;
        height = size().height;
        fmetrics = getFontMetrics(nf);
        message_width = fmetrics.stringWidth(message);
        img = createImage(message_width, height);
        offScreeng = img.getGraphics();
        offScreeng.setFont(nf);
        offScreeng.setColor(bgc);
        offScreeng.fillRect(0, 0, message_width, height);
        offScreeng.setColor(fgc);
        setFont(nf);
        X = width;
        hiz = Long.valueOf(getParameter("delay_time")).longValue();
        int i = fmetrics.getDescent() + fmetrics.getAscent();
        int j = (height - i) / 2;
        offScreeng.drawString(message, 0, i + j - fmetrics.getDescent());
        offScreeng.dispose();
    }

    public boolean mouseEnter(Event event, int i, int j)
    {
        stop();
        return true;
    }

    public boolean mouseExit(Event event, int i, int j)
    {
        start();
        return true;
    }

    public boolean mouseDown(Event event, int i, int j)
    {
        return true;
    }

    public void update(Graphics g)
    {
        X--;
        if (X < -message_width)
        {
            X = width;
        }
        paint(g);
    }

    public void paint(Graphics g)
    {
        g.drawImage(img, X, 0, this);
    }

    public void start()
    {
        if (runner == null)
        {
            runner = new Thread(this);
            runner.start();
        }
    }

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

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

    public myScroll()
    {
    }
}
