|
Das ist eine nicht alltägliche Laufschrift, die
von unten nach oben scrollt. Und das ist der ganze Quelltext (auch zum download):
/*
*
* Copyright (c) 1996 - 1998
* Frank Buss (fb@frank-buss.de), Stephan Schloepke (stephan@nordrhein.net)
*
* This applet was published in the book:
*
* "Programmier Training Java, In 15 Stunden topfit"
* ISBN 3-8158-1303-4
* Authors: Frank Buss, Stephan Schloepke
* Data Becker Verlage (http://www.databecker.de)
*
* You can get this applet and more at http://www.frank-buss.de
*
*/
//
// Der ultimative WaveScroller mal nach oben
//
import java.applet.*;
import java.awt.*;
public class WaveScrollY extends Applet implements Runnable {
private Thread Animation;
private Image Buffer;
private Graphics gBuffer;
private char [] laufText;
private int textHoehe;
private int textPos;
private int pixelPos;
private double sin=0.0;
private double sinOff;
private int xZentrum;
private int sinAmp;
private double zeichenOff;
private int textBreite;
private int stauchung;
private int geschwindigkeit;
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) {
try {
Animation.sleep (25);
} catch (Exception e) { }
repaint();
}
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
g.drawImage (Buffer,0,0, this);
zeichneLaufschrift();
}
private String getStringParam(String name, String standardWert) {
String param=getParameter(name);
if (param==null) return standardWert;
return param;
}
private int getIntParam(String name, int standardWert) {
String param=getParameter(name);
if (param==null) return standardWert;
return (Integer.parseInt(param,10));
}
public void init() {
setBackground(Color.black);
setForeground(Color.red);
String text=getStringParam("Text","KEIN TEXT IN DER HTML SEITE !!! ");
String fontName=getStringParam("Zeichensatz","Courier");
int fontGroesse=getIntParam("ZeichenGroesse",20);
sinOff=getIntParam("SinusOffset",2) * Math.PI / 180;
zeichenOff=getIntParam("ZeichenOffset",10) * Math.PI / 180;
stauchung=getIntParam("Stauchung",0);
geschwindigkeit=getIntParam("Geschwindigkeit",2);
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
gBuffer.setFont(new Font(fontName,Font.PLAIN,fontGroesse));
textHoehe=gBuffer.getFontMetrics().getHeight();
textBreite=gBuffer.getFontMetrics().getMaxAdvance();
sinAmp=(size().width-textBreite)>>1;
xZentrum=size().width>>1;
for (int c=0;c<=size().height/(textHoehe-stauchung);c++) text=" "+text;
laufText=new char[text.length()];
text.getChars(0,text.length(),laufText,0);
}
private void zeichneLaufschrift() {
gBuffer.setColor(getBackground());
gBuffer.fillRect(0,0,size().width,size().height);
gBuffer.setColor(getForeground());
pixelPos-=geschwindigkeit;
if (pixelPos<0) {
textPos++;
if (textPos>=laufText.length) textPos=0;
pixelPos=textHoehe-stauchung;
}
int tPos=textPos;
for (int yPos=pixelPos;yPos<=size().height+textHoehe;yPos+=textHoehe-stauchung) {
if (tPos==laufText.length) tPos=0;
int xPos = xZentrum + (int) (sinAmp * Math.sin (sin+tPos*zeichenOff));
xPos-=gBuffer.getFontMetrics().charWidth(laufText[tPos])>>1;
gBuffer.drawChars(laufText,tPos,1,xPos,yPos);
tPos++;
}
sin += sinOff;
}
}
|