FileDocCategorySizeDatePackage
HelloWeb4.javaAPI DocExample1783Sat Apr 04 02:58:24 BST 1998None

HelloWeb4

public class HelloWeb4 extends Applet implements ActionListener, Runnable, MouseMotionListener

Fields Summary
int
messageX
int
messageY
String
theMessage
Button
theButton
int
colorIndex
static Color[]
someColors
Thread
blinkThread
boolean
blinkState
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

		if ( e.getSource() == theButton ) {
			changeColor();
		}
	
private synchronized voidchangeColor()

		if ( ++colorIndex == someColors.length )
			colorIndex = 0;
		theButton.setForeground( currentColor() );
		repaint();
	
private synchronized java.awt.ColorcurrentColor()

		return someColors[ colorIndex ];
	
public voidinit()


	   
		theMessage = getParameter("message");
		theButton = new Button("Change Color");
		add(theButton);

		addMouseMotionListener(this);
		theButton.addActionListener(this);
	
public voidmouseDragged(java.awt.event.MouseEvent e)

		messageX = e.getX(); 
		messageY = e.getY();
		repaint();
	
public voidmouseMoved(java.awt.event.MouseEvent e)

 
public voidpaint(java.awt.Graphics graphics)

		graphics.setColor( blinkState ? Color.white : currentColor() );
		graphics.drawString( theMessage, messageX, messageY );
	
public voidrun()

		while ( true ) {
			blinkState = !blinkState;
			repaint();
			try {  
				Thread.sleep(500); 
			} catch (Exception e ) { 
				System.out.println( e );
			}
		}
	
public voidstart()

		if ( blinkThread == null ) {
			blinkThread = new Thread(this);
			blinkThread.start();
		}
	
public voidstop()

		if ( blinkThread != null ) {
			blinkThread.stop();
			blinkThread = null;
		}