FileDocCategorySizeDatePackage
NervousText.javaAPI DocSun JDK 1.5.0 Example5764Sat Jan 08 15:09:03 GMT 2005None

NervousText

public class NervousText extends Applet implements MouseListener, Runnable
An applet that displays jittering text on the screen.
author
Daniel Wyszynski 04/12/95
version
1.10, 02/05/97
modified
05/09/95 kwalrath Changed string; added thread suspension
modified
02/06/98 madbot removed use of suspend and resume and cleaned up

Fields Summary
String
banner
char[]
bannerChars
char[]
attributes
Thread
runner
boolean
threadSuspended
static final int
REGULAR_WD
static final int
REGULAR_HT
static final int
SMALL_WD
static final int
SMALL_HT
Font
regularFont
Font
smallFont
Constructors Summary
Methods Summary
public voiddestroy()

        removeMouseListener(this);
    
public java.lang.StringgetAppletInfo()

        return "Title: NervousText\nAuthor: Daniel Wyszynski\nDisplays a text banner that jitters.";
    
public java.lang.String[][]getParameterInfo()

        String pinfo[][] = {
            {"text", "string", "Text to display"},
        };
        return pinfo;
    
public voidinit()


       
	banner = getParameter("text");
	if (banner == null) {
	    banner = "HotJava";
	}

        int bannerLength = banner.length();
	StringBuffer bc = new StringBuffer(bannerLength);
	StringBuffer attrs = new StringBuffer(bannerLength);
	int wd = 0;
	for (int i = 0; i < bannerLength; i++) {
	    char c = banner.charAt(i);
	    char a = 0;
	    if (c == '^") {
		i++;
		if (i < bannerLength) {
		    c = banner.charAt(i);
		    a = '^";
		    wd += SMALL_WD - REGULAR_WD;
		} else {
		    break;
		}
	    }
	    bc.append(c);
	    attrs.append(a);
	    wd += REGULAR_WD;
	}

	bannerLength = bc.length();
	bannerChars =  new char[bannerLength];
	attributes = new char[bannerLength];
	bc.getChars(0, bannerLength, bannerChars, 0);
	attrs.getChars(0, bannerLength, attributes, 0);

        threadSuspended = false;
	resize(wd + 10, 50);
	addMouseListener(this);
    
public voidmouseClicked(java.awt.event.MouseEvent e)

    
public voidmouseEntered(java.awt.event.MouseEvent e)

    
public voidmouseExited(java.awt.event.MouseEvent e)

    
public synchronized voidmousePressed(java.awt.event.MouseEvent e)

        e.consume();
        threadSuspended = !threadSuspended;
        if (!threadSuspended)
            notify();
    
public voidmouseReleased(java.awt.event.MouseEvent e)

    
public voidpaint(java.awt.Graphics g)

	int length = bannerChars.length;
        for (int i = 0, x = 0; i < length; i++) {
	    int wd, ht;
	    if (attributes[i] == '^") {
		wd = SMALL_WD;
		ht = SMALL_HT;
		g.setFont(smallFont);
	    } else {
		wd = REGULAR_WD;
		ht = REGULAR_HT;
		g.setFont(regularFont);
	    }
            int px = (int) (10 * Math.random() + x);
            int py = (int) (10 * Math.random() + ht);
            g.drawChars(bannerChars, i, 1, px, py);
	    x += wd;
	}
    
public voidrun()

        Thread me = Thread.currentThread();
        while (runner == me) {
            try {
                Thread.sleep(100);
                synchronized(this) {
                    while (threadSuspended) {
                        wait();
                    }
                }
            } catch (InterruptedException e){
            }
            repaint();
        }
    
public voidstart()

        runner = new Thread(this);
        runner.start();
    
public synchronized voidstop()

	runner = null;
        if (threadSuspended) {
            threadSuspended = false;
            notify();
        }