home *** CD-ROM | disk | FTP | other *** search
- DEF_COMPONENTNAME
- Blink
- DEF_SUPERCLASS
- Applet
- DEF_SUPERCOMPONENT
-
- DEF_PACKAGE
- plugins
- widgets
- DEF_ENDLIST
- DEF_SUBCOMPONENTLIST
- DEF_ENDLIST
- DEF_SUBCOMPONENTCLASSLIST
- DEF_ENDLIST
- DEF_CATEGORY
- Widgets
- DEF_BITMAP
- blinkm.bmp
- DEF_THUMBNAIL_UP
- blktxt2.bmp
- DEF_THUMBNAIL_DOWN
- 2-blktxt2.bmp
- DEF_VISUAL
- DEF_TOOL
- DEF_IMPORTS
- java.util.StringTokenizer
- DEF_ENDLIST
- DEF_REQUIRES
- DEF_ENDLIST
- DEF_IMPLEMENTS
- Runnable
- DEF_ENDLIST
- DEF_DECLARATION
- // A class that produces a blinking text component .
- // Variable Declarations
- Thread blinker;
- String lbl;
- Font font;
- int speed;
- String att1;
- String att2;
- DEF_ENDLIST
- DEF_METHOD
- void initialize() {
- font = new java.awt.Font("TimesRoman", Font.PLAIN, 24);
- speed = (att1 == null) ? 400 : (1000 / Integer.valueOf(att1).intValue());
- lbl = (att2 == null) ? "Blink" : att2;
- start();
- }
- DEF_ENDLIST
- DEF_METHOD
- public void paint(Graphics g) {
- int x = 0, y = font.getSize(), space;
- int red = (int)(Math.random() * 50);
- int green = (int)(Math.random() * 50);
- int blue = (int)(Math.random() * 256);
- Dimension d = size();
-
- g.setColor(Color.black);
- g.setFont(font);
- FontMetrics fm = g.getFontMetrics();
- space = fm.stringWidth(" ");
- for (StringTokenizer t = new StringTokenizer(lbl) ; t.hasMoreTokens() ; ) {
- String word = t.nextToken();
- int w = fm.stringWidth(word) + space;
- if (x + w > d.width) {
- x = 0;
- y += font.getSize();
- }
- if (Math.random() < 0.5) {
- g.setColor(new java.awt.Color((red + y * 30) % 256, (green + x / 3) % 256, blue));
- } else {
- g.setColor(Color.lightGray);
- }
- g.drawString(word, x, y);
- x += w;
- }
- }
- DEF_ENDLIST
- DEF_METHOD
- public void start() {
- blinker = new Thread(this);
- blinker.start();
- }
- DEF_ENDLIST
- DEF_METHOD
- public void stop() {
- blinker.stop();
- }
- DEF_ENDLIST
- DEF_METHOD
- public void run() {
- while (true) {
- try {Thread.currentThread().sleep(speed);} catch (InterruptedException e){}
- repaint();
- }
- }
- DEF_ENDLIST
- DEF_METHOD
- public void setSpeed(String aParam) {
- att1 = aParam;
- } //setSpeed
- DEF_ENDLIST
- DEF_METHOD
- public void setLabel(String aParam) {
- att2 = aParam;
- } //setSpeed
- DEF_ENDLIST
- DEF_PROPERTY
- Text
- String
- setLabel(AVALUE);
-
- Hello!
- DEF_ENDLIST
- DEF_PROPERTY
- Speed
- String
- setSpeed(AVALUE);
-
- 100
- DEF_ENDLIST
- DEF_PROPERTY
- Top
- int
- move(bounds().x, AVALUE);
- AVALUE = bounds().y;
- 0
- DEF_ENDLIST
- DEF_PROPERTY
- Left
- int
- move(AVALUE, bounds().y);
- AVALUE = bounds().x;
- 0
- DEF_ENDLIST
- DEF_PROPERTY
- Height
- int
- resize(bounds().width, AVALUE);
- AVALUE = bounds().height;
- 50
- DEF_ENDLIST
- DEF_PROPERTY
- Width
- int
- resize(AVALUE, bounds().height);
- AVALUE = bounds().width;
- 150
- DEF_ENDLIST
- DEF_ENDCOMPONENT
-