// RunningText.java: Applet

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

public class RunningText extends Applet implements Runnable
{
private Thread m_RunningText = null;
String m_string = "Willkommen im Jahr 2000!";
String m_font = "Helvetica";
int m_size = 12;
int m_fps = 50;
private int m_nOffset;
private int m_nMax;
private int m_nMin;
int nCounter=0;
boolean nHochzaehlen=true;
Image m_image;
Graphics m_g;
int m_breite;
int m_hoehe;


public RunningText()
{
}


public String getAppletInfo()
{
return "BN\r\n" +
"Copyright (c) 2000";
}


public void init()
{
resize(320, 20);
Font font = new Font(m_font, Font.PLAIN, m_size);
setFont(font);

//this.setForeground(Color.red);
//this.setBackground(Color.white);

FontMetrics fm = getFontMetrics(font);
m_nMin = -fm.stringWidth(m_string);
m_nMax = size().width;
m_nOffset = m_nMax;
m_breite = size().width;
m_hoehe = size().height;
m_image = createImage(m_breite, m_hoehe);
m_g = m_image.getGraphics();

}


public void destroy()
{
}


public void update(Graphics g)
{
int nVertOffset = size().height;
int nWert;


if(nHochzaehlen==true){
nCounter++;
} else {
nCounter--;
}
if(nCounter>255){
nCounter = 255;
nHochzaehlen = false;
} else if(nCounter<0){
nCounter = 0;
nHochzaehlen = true;
}
Color Color1 = new Color(nCounter, 0, 0);


nWert = nCounter;
if(nWert<220){
nWert = 220;
}
Color Color2 = new Color(nWert, nWert, nWert);
m_g.setColor(Color2);
m_g.fillRect(0, 0, m_breite, m_hoehe);


nVertOffset = (nVertOffset - m_size) / 2;
m_g.setColor(Color1);
m_g.drawString(m_string, m_nOffset, nVertOffset + m_size);
m_nOffset--;
if(m_nOffset<m_nMin){
m_nOffset = m_nMax;
}
paint(g);
}


public void paint(Graphics g)
{
if(m_image!=null){
g.drawImage(m_image, 0, 0, null);
}
}


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


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

}


public void run()
{


while (true)
{
int nSleepValue = 1000 / m_fps;

try
{
repaint();
Thread.sleep(nSleepValue);
}
catch (InterruptedException e)
{
stop();
}
}
}
}