home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09961.iso / java / mojo1-2e.exe / MOJODISK / DATA.4 / plugins / blink.def next >
Encoding:
Text File  |  1996-07-01  |  2.8 KB  |  152 lines

  1. DEF_COMPONENTNAME
  2. Blink
  3. DEF_SUPERCLASS
  4. Applet
  5. DEF_SUPERCOMPONENT
  6.  
  7. DEF_PACKAGE
  8. plugins
  9. widgets
  10. DEF_ENDLIST
  11. DEF_SUBCOMPONENTLIST
  12. DEF_ENDLIST
  13. DEF_SUBCOMPONENTCLASSLIST
  14. DEF_ENDLIST
  15. DEF_CATEGORY
  16. Widgets
  17. DEF_BITMAP
  18. blinkm.bmp
  19. DEF_THUMBNAIL_UP
  20. blktxt2.bmp
  21. DEF_THUMBNAIL_DOWN
  22. 2-blktxt2.bmp
  23. DEF_VISUAL
  24. DEF_TOOL
  25. DEF_IMPORTS
  26. java.util.StringTokenizer
  27. DEF_ENDLIST
  28. DEF_REQUIRES
  29. DEF_ENDLIST
  30. DEF_IMPLEMENTS
  31. Runnable
  32. DEF_ENDLIST
  33. DEF_DECLARATION
  34. // A class that produces a blinking text component .
  35. //  Variable Declarations
  36.     Thread blinker;
  37.     String lbl;
  38.     Font font;
  39.     int speed;
  40.     String att1;
  41.     String att2;
  42. DEF_ENDLIST
  43. DEF_METHOD
  44.     void initialize() {
  45.     font = new java.awt.Font("TimesRoman", Font.PLAIN, 24);
  46.     speed = (att1 == null) ? 400 : (1000 / Integer.valueOf(att1).intValue());
  47.     lbl = (att2 == null) ? "Blink" : att2;
  48.     start();
  49.     }
  50. DEF_ENDLIST
  51. DEF_METHOD
  52.     public void paint(Graphics g) {
  53.     int x = 0, y = font.getSize(), space;
  54.     int red = (int)(Math.random() * 50);
  55.     int green = (int)(Math.random() * 50);
  56.     int blue = (int)(Math.random() * 256);
  57.     Dimension d = size();
  58.  
  59.     g.setColor(Color.black);
  60.     g.setFont(font);
  61.     FontMetrics fm = g.getFontMetrics();
  62.     space = fm.stringWidth(" ");
  63.     for (StringTokenizer t = new StringTokenizer(lbl) ; t.hasMoreTokens() ; ) {
  64.         String word = t.nextToken();
  65.         int w = fm.stringWidth(word) + space;
  66.         if (x + w > d.width) {
  67.         x = 0;
  68.         y += font.getSize();
  69.         }
  70.         if (Math.random() < 0.5) {
  71.         g.setColor(new java.awt.Color((red + y * 30) % 256, (green + x / 3) % 256, blue));
  72.         } else {
  73.         g.setColor(Color.lightGray);
  74.         }
  75.         g.drawString(word, x, y);
  76.         x += w;
  77.     }
  78.     }
  79. DEF_ENDLIST
  80. DEF_METHOD
  81.     public void start() {
  82.     blinker = new Thread(this);
  83.     blinker.start();
  84.     }
  85. DEF_ENDLIST
  86. DEF_METHOD
  87.     public void stop() {
  88.     blinker.stop();
  89.     }
  90. DEF_ENDLIST
  91. DEF_METHOD
  92.     public void run() {
  93.     while (true) {
  94.     try {Thread.currentThread().sleep(speed);} catch (InterruptedException e){}
  95.         repaint();
  96.     }
  97.     }
  98. DEF_ENDLIST
  99. DEF_METHOD
  100. public void setSpeed(String aParam) {
  101.     att1 = aParam;
  102.   } //setSpeed
  103. DEF_ENDLIST
  104. DEF_METHOD
  105. public void setLabel(String aParam) {
  106.     att2 = aParam;
  107.   } //setSpeed
  108. DEF_ENDLIST
  109. DEF_PROPERTY
  110. Text
  111. String
  112. setLabel(AVALUE);
  113.  
  114. Hello!
  115. DEF_ENDLIST
  116. DEF_PROPERTY
  117. Speed
  118. String
  119. setSpeed(AVALUE);
  120.  
  121. 100
  122. DEF_ENDLIST
  123. DEF_PROPERTY
  124. Top
  125. int
  126. move(bounds().x, AVALUE);
  127. AVALUE = bounds().y;
  128. 0
  129. DEF_ENDLIST
  130. DEF_PROPERTY
  131. Left
  132. int
  133. move(AVALUE, bounds().y);
  134. AVALUE = bounds().x;
  135. 0
  136. DEF_ENDLIST
  137. DEF_PROPERTY
  138. Height
  139. int
  140. resize(bounds().width, AVALUE);
  141. AVALUE = bounds().height;
  142. 50
  143. DEF_ENDLIST
  144. DEF_PROPERTY
  145. Width
  146. int
  147. resize(AVALUE, bounds().height);
  148. AVALUE = bounds().width;
  149. 150
  150. DEF_ENDLIST
  151. DEF_ENDCOMPONENT
  152.