Cross Fader


Java Source:

//
// Text fader
//
// (C)1999
// Brian Postma
// b.postma@hetnet.nl
//

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

public class Fader extends Applet implements Runnable
{
  Dimension	d;
  Image         ii;
  Graphics      goff;
  Thread	thethread;
  Font 		font = new Font("Helvetica", Font.BOLD, 36);
  FontMetrics	fm;  
  String	s1;
  String	s2;
  int		color1, color2;
  int		dcolor1, dcolor2;

  public String getAppletInfo()
  {
    return("Text fader - by Brian Postma");
  }

  public void init()
  {
    Graphics    g;
    int		i;
    d = size();
    g=getGraphics();
    g.setFont(font);
    fm = g.getFontMetrics();
    setBackground(Color.black);
    s1=getParameter("Text1");
    s2=getParameter("Text2");
    color1=10;
    color2=245;
    dcolor2=-2;
    dcolor1=2;
  }

  public void paint(Graphics g)
  {
    if (goff==null && d.width>0 && d.height>0)
    {
      ii = createImage(d.width, d.height);
      goff = ii.getGraphics();
    }
    if (goff==null || ii==null)
      return;

    g.setFont(font);
    goff.setFont(font);

    if (color1=250)
      dcolor1=-dcolor1;
    if (color2<=3 || color2>=250)
      dcolor2=-dcolor2;
  }

  public void run()
  {
    long  starttime;
    Graphics g;
 
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    g=getGraphics();
    while(true)
    {
      starttime=System.currentTimeMillis();
      try
      {
        paint(g);
        starttime += 20;
        Thread.sleep(Math.max(0, starttime-System.currentTimeMillis()));
      }
      catch (InterruptedException e)
      {
        break;
      }
    }
  }

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

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


How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.