Debian Codegraph @

rhino/examples/NervousText.js

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 // The Java "NervousText" example ported to JavaScript.
6 // Compile using java org.mozilla.javascript.tools.jsc.Main -extends java.applet.Applet -implements java.lang.Runnable NervousText.js
7 /*
8 Adapted from Java code by
9 Daniel Wyszynski
10 Center for Applied Large-Scale Computing (CALC)
11 04-12-95
12
13 Test of text animation.
14
15 kwalrath: Changed string; added thread suspension. 5-9-95
16 */
17 var Font = java.awt.Font;
18 var Thread = java.lang.Thread;
19 var separated;
20 var s = null;
21 var killme = null;
22 var i;
23 var x_coord = 0, y_coord = 0;
24 var num;
25 var speed=35;
26 var counter =0;
27 var threadSuspended = false; //added by kwalrath
28
29 function init() {
30 this.resize(150,50);
31 this.setFont(new Font("TimesRoman",Font.BOLD,36));
32 s = this.getParameter("text");
33 if (s == null) {
34 s = "Rhino";
35 }
36 separated = s.split('');
37 }
38
39 function start() {
40 if(killme == null)
41 {
42 killme = new java.lang.Thread(java.lang.Runnable(this));
43 killme.start();
44 }
45 }
46
47 function stop() {
48 killme = null;
49 }
50
51 function run() {
52 while (killme != null) {
53 try {Thread.sleep(100);} catch (e){}
54 this.repaint();
55 }
56 killme = null;
57 }
58
59 function paint(g) {
60 for(i=0;i<separated.length;i++)
61 {
62 x_coord = Math.random()*10+15*i;
63 y_coord = Math.random()*10+36;
64 g.drawChars(separated, i,1,x_coord,y_coord);
65 }
66 }
67
68 /* Added by kwalrath. */
69 function mouseDown(evt, x, y) {
70 if (threadSuspended) {
71 killme.resume();
72 }
73 else {
74 killme.suspend();
75 }
76 threadSuspended = !threadSuspended;
77 return true;
78 }
79