home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / INTERNET / WASTEF_1.ZIP / WASTEF~1.JAV
Encoding:
Text File  |  1996-04-27  |  2.2 KB  |  79 lines

  1. /* Wasteful.java by Mark D. LaDue */
  2.  
  3. /* February 17, 1996 */
  4.  
  5. /*  Copyright (c) 1996 Mark D. LaDue
  6.     You may study, use, modify, and distribute this example for any purpose.
  7.     This example is provided WITHOUT WARRANTY either expressed or implied.  */
  8.  
  9. /* This  Java Applet is intended to bring your Java-aware
  10.    browser to its knees by hogging the CPU.  Note that you can
  11.    suspend its effects because it has a mouseDown() method.  */
  12.  
  13. import java.awt.Color;
  14. import java.awt.Event;
  15. import java.awt.Font;
  16. import java.awt.Graphics;
  17. import java.awt.Image;
  18.  
  19. public class Wasteful extends java.applet.Applet implements Runnable {
  20.     Font wordFont = new Font("TimesRoman", Font.PLAIN, 12);
  21.     Thread wasteResources = null;
  22.     Image offscreenImage;
  23.     Graphics offscreenGraphics;
  24.     boolean threadStopped = false;
  25.     StringBuffer holdResults = new StringBuffer(0);
  26.     long n = 0;
  27.     int delay;
  28.  
  29.     public void init() {
  30.     setBackground(Color.blue);
  31.     offscreenImage = createImage(this.size().width, this.size().height);
  32.     offscreenGraphics = offscreenImage.getGraphics();
  33.     String str = getParameter("wait");
  34.     if (str == null)
  35.         delay = 0;
  36.     else delay = (1000)*(Integer.parseInt(str));
  37.     }
  38.  
  39.     public void start() {
  40.         if (wasteResources == null) {
  41.         wasteResources = new Thread(this);
  42.         wasteResources.setPriority(Thread.MAX_PRIORITY);
  43.         wasteResources.start();
  44.         }
  45.     }
  46.  
  47.     public void stop() {} //doesn't stop anything
  48.  
  49.  
  50.     public void run() {
  51.         try {Thread.sleep(delay);}
  52.         catch(InterruptedException e) {}
  53.         while (n >= 0) {
  54.         holdResults.append(fibonacci(n));
  55.         repaint();
  56.         n++;
  57.         }
  58.     }
  59.  
  60.     public void update(Graphics g) {
  61.         paint(g);
  62.     }
  63.  
  64.     public void paint(Graphics g) {
  65.  
  66.      offscreenGraphics.drawRect(0, 0, this.size().width, this.size().height);
  67.      offscreenGraphics.setColor(Color.blue);
  68.      offscreenGraphics.drawString(holdResults.toString(), 10, 10);
  69. //     g.drawImage(offscreenImage, 0, 0, this);
  70.     }
  71.  
  72.     public long fibonacci(long k) {
  73.         if (k == 0 || k == 1)
  74.             return k;
  75.         else
  76.             return fibonacci(k - 1) + fibonacci(k - 2);
  77.     }
  78. }
  79.