String s = "...";
char[] arr = s.toCharArray();
long timeout = 100;
for (int i = 0; i < arr.length; i++)
{
System.out.print(arr[i]);
wait(timeout);
}
This would accomplish on 8 lines what the other class uses about 30 lines
for (- it is an applet and also contains parameters -).
When I compile this, I get:
non-static method wait cannot be referenced from a static context.
This is easily solved by removing static from the method definition, but the
thing is it seems to cascade all the way through to the main method, which
HAS to be static.
So I started looking and came out on threads.
Once the class was made an extension of Thread, it compiled fine.
When running however, an error is returned telling me I don't have
ownership:
java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.wait(Native Method)
at CharDraw.run(CharDraw.java:18)
at java.lang.Thread.run(Thread.java:484)
Does anyone know how I can give ownership of the object to the thread - or -
how I can correctly continue using my first idea?
Thanks.
"Stijn Verholen" <sver...@easynet.be> wrote in message
news:9rh3g7$28s4$1...@rivage.news.be.easynet.net...
So make an instance and call a method on it:
class Foo
{
public static void main(String[] args)
{
new Foo().method();
}
void method()
{
System.out.println("This is an instance method.");
}
}
You should probably get one or more Java books and read them.
Marshall
> java.lang.IllegalMonitorStateException: current thread not owner
> at java.lang.Object.wait(Native Method)
> at CharDraw.run(CharDraw.java:18)
> at java.lang.Thread.run(Thread.java:484)
>
> Does anyone know how I can give ownership of the object to the thread - or -
> how I can correctly continue using my first idea?
You need to look into the use if synchronized.
--
Tor Iver Wilhelmsen <to...@chello.no>
So the fruits of your labors have fermented into wine
And the sweat that was dripped is now the honey of the hive
- Clutch: High Caliber Consecrator
The problem is that you're using wait(long). You want to be using
java.lang.Thread.sleep(long) instead. That will require you to catch
InterruptedException, but that's not a big deal.
The basic issue is that the various forms of java.lang.Object.wait() are NOT
for timed pauses. It is half of java's inter-thread semaphore mechanism,
which is complete with java.lang.Object.notify() or notifyAll(). I'd
recommend picking up the Java Threads book by O'Reilly to learn about that,
if you're interested.
Hello again. I notice you've asked the same question as you did before.
Any reason for ignoring the answers you were given then?
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too