I am trying to learn how to use threads in applets so I am looking at some old examples (from 1999) from the java.sun pages. I have JDK 1.5, and they will compile ok, but when I try to run the applet it complains and gives me this error java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
Here is what I have
class ThisPanel extends Panel implements Runnable{
Thread thread;
publicvoid run() {
Thread me = Thread.currentThread();
while (thread == me) {
// CALL A METHOD
try {
Thread.sleep(100);
} catch (InterruptedException e) {
break;
}
}
} // END OF RUN
publicvoid start() {
thread = new Thread(this);
thread.start();
}
publicvoid stop() {
thread = null;
}
}
and the call from the applet class
ThisPanel panel;
publicvoid start() {
panel.start();
}
any thoughts on why this is happening, and how I can use a simple thread like this one in a JApplet?
Thanks for the advice, but that was actually just a typo posting it.
I tried a few other things, including the SwingWorker class that is on the swing webpages, but I always get that AccessControlException when I try to run the applet
They do work when I just write them as a normal application with a main method. Is there something else that I need to know about using threads in applets?
I figured it out!! there is nothing wrong with my thread code, it is just the applet viewer and/or NetBeans that doesn't like it. The applet works fine if I open the HTML file in my web browser.
You are getting a security exception. This is due to the JRE's security settings. By default applet security is quite strict and only allows you to play in the "sandbox". I think you need to sign the applet and include different security settings to modify the ThreadGroup.