/* A simple banner applet. TEXT pp. 623-625

   This applet creates a thread that scrolls
   the message contained in msg right to left
   across the applet's window.
   filename: SimpleBanner.java
*/
import java.awt.*;
import java.applet.*;
public class SimpleBanner extends Applet implements Runnable {
  String msg = " Moving Object ";
  Thread t = null;
  int state;
  boolean stopFlag;

  // Set colors and initialize thread.
  public void init() {
    setBackground(Color.cyan);
    setForeground(Color.red);
  }

  // Start thread
  public void start() {
    t = new Thread(this);
    stopFlag = false;
    t.start();
  }

  // Entry point for the thread that runs the banner.
  public void run() {
    char ch;

    // Display banner 
    for( ; ; ) {
      try {
        repaint();
        Thread.sleep(250);
        ch = msg.charAt(0);
        msg = msg.substring(1, msg.length());
        msg += ch;
        if(stopFlag)
          break;
      } catch(InterruptedException e) {}
    }
  }

  // Pause the banner.
  public void stop() {
    stopFlag = true;
    t = null;
  }

  // Display the banner.
  public void paint(Graphics g) {
    g.setFont(new Font("Courier", Font.BOLD, 60));
    g.drawString(msg, 50, 80);
  }
}

//filename: RotaryPieApplet.java
import java.awt.*;
import java.applet.Applet;
public class RotaryPieApplet extends Applet implements Runnable {

  Thread t = null;

  boolean stopFlag;
  public Pie p1;   
    
  public void init() {
    p1 = new Pie(35,35,200,0,40,Color.black,Color.blue,Color.white); 
    setBackground(Color.green);
  }

  public void start() {
    t = new Thread(this);
    stopFlag = false;
    t.start();
  }

  public void run() {
    int angle = 1;

    // Display banner 
    for( ; ; ) {
      try {
        repaint();
        Thread.sleep(150);
        p1.angle = angle++ % 360;
        if(stopFlag)
          break;
      } catch(InterruptedException e) {}
    }
  }

  // Pause the banner.
  public void stop() {
    stopFlag = true;
    t = null;
  }

  public void paint ( Graphics g ) {
	p1.drawPie(g); 
  }
}

Previou page Next page