Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simple syntax for applet insertion: still not quite there



I got the following suggested sleep applet:

 

import java.applet.Applet;

import java.awt.*;

import java.io.PrintStream;

 

public class Sleeper extends Applet implements Runnable {

 

Thread runner;

public void init() {}

public void sleep() {

long intime = System.currentTimeMillis();

System.out.println("Before sleep");

try { Thread.currentThread().sleep(2500); }

catch (InterruptedException iex) { iex.printStackTrace(); }

System.out.println("After sleep elapsed" + (System.currentTimeMillis() - intime));

runner = new Thread(this);

runner.start();

}

public void run() {

while (true) {

try {

Thread.currentThread().sleep(500);

}

catch (InterruptedException iex) { iex.printStackTrace(); }

}

}

}

 

Which I’ve since converted to:

 

// PauseHack.java

 

import java.applet.Applet;

import java.awt.*;

import java.io.PrintStream;

 

public class PauseHack extends Applet implements Runnable {

 

Thread runner;

public void init() {}

public void sleep(int milliseconds) {

  try {

    Thread.currentThread().sleep(milliseconds);

  } catch (InterruptedException iex) {

    iex.printStackTrace();

  }

  runner = new Thread(this);

  runner.start();

  }

 

public void run() {

    while (true) {

      try {

        Thread.currentThread().sleep(500);

      } catch (InterruptedException iex) { iex.printStackTrace(); }

    }

  }

}

 

// end of PauseHack.java

 

And after fiddling with it the applet tag no longer bombs out my page:

 

<applet code='PauseHack.class' codebase='' name='pausehackhandle'></applet>

 

And the _javascript_ I’m calling it with is as follows:

 

      document.pausehackhandle.sleep(numberMillis);

 

This seems all right, but somehow I’m still not getting the sleep.  Does anyone see the source of my mistake?  I’m stumped, but I’m afraid there’s some subtle thing with my Java threads code in the second example above.  For all I know it might be the position of the moon.  I am  getting mildly desperate.  The rest of my tests have been working under XP FF and IE, where I have other alternatives for my pausehack call, but this one is necessary for Safari.

 

Sincerely, Xeno

xc

 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.