Multithreadded applet just will not die. Why?

Hi!
The applet code is below. In short, it
has four classes:
Mulka - a simple graphic object to draw (basically
a cross)
DaThing - a Thread class which draws many many
Mulkas
AnotherThing - a thread class which draws a
string on top of mulkas.
And, of course, the main applet class.
The main applet class create two objects: one
instance of DaThing and on instance of
AnotherThing then starts them both. So, they
are drawing at the same time. After that
the applet does not do a thing. However, it
handles mouseDown event and if the mouse
got down 5 times the applet stops the
threads and stops itself.
The problem is that IT DOES stop the
threads but continues to execute itself, so,
clicking the mouse will still draw a box and
repaint the applet graphics area. Why is that?
How do i completely stop the applet?
Regards,
Artem
import java.applet.*;
import java.awt.*;
import java.util.*;
// graphics object to draw
public class Mulka {
       private int x,y;
       private int hx,hy;
       private final int width=16;
       private final int height=16;
       private Color bgcolor;
       private Color color;
       public void setcolor (Color c){
              color=c;
       public void setxy(int x, int y) {
              this.x=x;
              this.y=y;
       public void sethotspot(int x, int y) {
              hx=x;
              hy=y;
       public void setbgcolor (Color c){
              bgcolor=c;
       public void draw(Graphics g) {
              // a simple cross
              g.setColor(color);
              g.drawLine(x+hx,y+hy,x+width-1+hx,y+height-1+hy);
              g.drawLine(x+width-1+hx,y+hy,x+hx,y+height-1+hy);
       public void undraw(Graphics g) {
              g.setColor(bgcolor);
              g.drawLine(x+hx,y+hy,x+width-1+hx,y+height-1+hy);
              g.drawLine(x+width-1+hx,y+hy,x+hx,y+height-1+hy);
       public Mulka (int x, int y){
              hx=0;
              hy=0;
              color=Color.black;
              bgcolor=Color.white;
              this.x=x;
              this.y=y;
       public Mulka (){
              hx=0;
              hy=0;
              color=Color.black;
              bgcolor=Color.white;
              this.x=0;
              this.y=0;
public class AnotherThing extends Thread {
       Graphics g = null;
       String text;
       AnotherThing (String name){
                    super(name);
                    text=name;
       public void setg (Graphics g){
              this.g=g;
       public void run (){
              Random rand = new Random();
              while (true){
                    try{
                        g.setColor(                                      new Color(
                                           (int)(rand.nextFloat()*255),
                                           (int)(rand.nextFloat()*255),
                                           (int)(rand.nextFloat()*255)
                        g.drawString(text,50+(int)(rand.nextFloat()*5),50);
                    catch(InterruptedException e) {
                      this.stop();
public class DaThing extends Thread {
       Graphics g = null;
       Mulka mulkas[] = new Mulka[10];
       String text;
       DaThing (String name){
                    super(name);
                    text=name;
       public void setg (Graphics g){
              this.g=g;
       public void run (){
              int i;
              Random rand=new Random();
              while(true){
                          try{
                            for (i=0;i<10;i++){
                                mulkas=new Mulka();
mulkas[i].setxy(
(int)(rand.nextFloat()*300),
(int)(rand.nextFloat()*200));
mulkas[i].setcolor(
new Color(
(int)(rand.nextFloat()*255),
(int)(rand.nextFloat()*255),
(int)(rand.nextFloat()*255)
for (i=0;i<10;i++){
mulkas[i].draw(g);
catch(InterruptedException e) {
this.stop();
public class OffScreen extends Applet {
DaThing draw_thread = null;
AnotherThing thing= null;
int waitforclicks=5;
public void init () {
System.out.println("Applet inited");
waitforclicks=5;
resize(320,240);
public void start() {
System.out.println("Applet started");
if (draw_thread == null){
draw_thread = new DaThing("First thread");
draw_thread.setg(getGraphics());
draw_thread.start();
if (thing == null){
thing = new AnotherThing("Another thread");
thing.setg(getGraphics());
thing.start();
public void stop() {
if (draw_thread != null){
draw_thread.stop();
draw_thread=null;
if (thing != null){
thing.stop();
thing=null;
System.out.println("Applet finished");
public boolean mouseDown(Event evt, int x, int y){
Graphics g=getGraphics();
System.out.println("Clicked mouse");
g.fillRect(x,y,50,50);
repaint();
waitforclicks--;
if (waitforclicks<1){
System.out.println("This was the last click");
stop();
return true;

Thanks for replies.
As for exit then I think is should be done like
Runtime rt=getRuntime();
rt.exit(0);But it works only in debugger :( In a browser exit()
is just ignored.
So, basically, the only way to at least emulate
visually the death of an applet i should do something
like below (notice the isActive flag). Is it so?
import java.applet.*;
import java.awt.*;
import java.lang.*;
public class DieTest extends Applet {
       int count=5;
       int x=0;
       boolean isActive=true;
       public void init() {
              System.out.println("Applet inited");
       public void stop() {
              System.out.println("Applet Stopped");
       public boolean mouseDown(Event evt, int x, int y){
              Runtime a = Runtime.getRuntime();
              Graphics g=getGraphics();
              if (isActive==true){
                 count--;
                 System.out.println("Clicked mouse: "+x);
                 g.drawString(count+"",x,y);
                 if (count<1){
                    System.out.println("Clicked last time");
                    stop();
                    isActive=false;
              return true;
}

Similar Messages

  • I have a single song that is on my iPod Classic 7 but the artist does not appear and under "artists" in the music it doesn't appear, nor does it in albums. All the information on the song is correct the artist just will not appear. Why is this?

    All the information is correct and filled correctly, I have chacked seven times, but it still will not appear, why?

    Any funny characters in the artist or album names? I take it that it is not hiding for the reasons given in Missing Artist or Album not with others by same artist? Sort fields can sometimes cause items to be listed in a different place within the list. Can you find it using search on the device?
    tt2

  • I can't get home sharing to turn on on my computers. I have a PC running windows XP that has a large library on it that I want to access from a newer windows 7 PC. I have turned home sharing on in both, same apple ID. I just will not come up. Any ideas?

    I can't get home sharing to turn on on my computers. I have a PC running windows XP that has a large library on it that I want to access from a newer windows 7 PC. I have turned home sharing on in both, same apple ID. I just will not come up. Any ideas?

    Ugh, disregard.. it magically started working -_-

  • HT5631 how do I verify my apple id? I can't sign in to it in mail and I can't make a new one because it just will not process I'm trying to set up iCloud between iPad and iPhone and having ALOT of difficulty pleAse help need it done by later on today!!!!!

    how do I verify my apple id? I can't sign in to it in mail and I can't make a new one because it just will not process I'm trying to set up iCloud between iPad and iPhone and having ALOT of difficulty pleAse help need it done by later on today!!!!!

    In order to use your Apple ID to create an iCloud account, the primary email address associated with the ID must first be verified.  To do this, Apple will send a verification email to your account and you must respond to the email by clicking the Verify Now link.  Make sure you are check the spam/junk folder as well as the inbox.  If it isn't there, go to https://appleid.apple.com, click Manage your Apple ID, sign in, click on Name, ID and Email addresses on the left, then to the right click Resend under your Primary Email Address to resend the verification email.

  • Adobe bridge appears as a question mark on iMac dock and will not open, why?

    Adobe bridge appears as a question mark on iMac dock and will not open, why?

    Because your Bridge install is somehow messed up.
    BOILERPLATE TEXT:
    If you give complete and detailed information about your setup and the issue at hand, such as your platform (Mac or Win), exact versions of your OS, of Photoshop and of Bridge, machine specs, what troubleshooting steps you have taken so far, what error message(s) you receive, if having issues opening raw files also the exact camera make and model that generated them, etc., someone may be able to help you.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • Photoshop cs6 will not open, why?

    photoshop cs6 will not open, why?

    Did it ever work on you machine?  Do you get any error message?  What OS are you using? You provide no information to even give us a clue as to what might be going on,

  • The lock button on my Phone 5 has stopped working completely. It just will not work anymore so I have to rely on the auto-lock . Will apple replace me phone?

    I have an Iphone 5 on contract with T-mobile/EE. The lock button on my Phone 5 has stopped working completely. It just will not work anymore so I have to rely on the auto-lock . Will apple replace my phone or do I ahve to take it back to T-mobile? It is just short of a year into a 24 month contract.

    Yes; If it's under the one year hard ware warrnety and it doesn't have any damage on the device you can get it replaced, contact Apple ASAP

  • HT1399 When I import a CD to itunes, it splits the album in to multiple entries. I have changed the info on some but others just will not merge. Is there an easy way to do this and can I stop them from splitting in future? Thanks

    When I import a CD to itunes, it splits the album in to multiple entries. I have changed the info on some but others just will not merge. Is there an easy way to do this and can I stop them from splitting in future? Thanks

    Okay this is what fixed my problem. Some kind of error/glitch occured half-way through importing that third cd that prevented further imports from any other cd. Once I completely removed the half-imported cd album from my library I could further import cd's without any problems.

  • I have up dated my itune and now it will not play my old purchase movies. I have brought new ones and they work but my old purchases will not. Why and how can I fix it.

    I have up dated my itune and now it will not play my old purchase movies. I have brought new ones and they work but my old purchases will not. Why and how can I fix it.

    Contacts are designed to be synced to a supported application on the computer or a cloud service.
    Pictures taken with the device are designed to regularly be copied off the device to a computer as would be done with any digital camera.
    If you have failed to use the device as designed it may be too late to recovery anything.
    Is the device regularly backed up to a computer via iTunes?  If so, the most recent backup (when restored to a replacement iOS device) should contain all contacts and pictures as of when the backup was created.

  • I've tried reseting my sync accounts the way all of the help articles say, but my computer and two android devices just will not sync with this new FF Sync vers

    I've tried reseting my sync accounts the way all of the help articles say, but my computer and two android devices just will not sync with this new FF Sync version.
    I've tried unregistering the device sync accounts, removing the accounts, reinstalling FF on all devices, etc.
    Nothing works. Please help.

    Hi mongoose00318,
    On the android devices in the Account section of your OS settings, please make sure that the account is not listed under "Firefox Sync (deprecated)" this is the old sync. Firefox for Android may need to be reinstalled and the Firefox Sync (depricated) account removed from the device.
    NOTE: DO NOT do this if there is data on the devices that have not obviously synced yet. An alternative is to visit accounts.firefox.com to see if you are logged into the device on the new sync sign in page.
    Does this help?

  • I get: INVALD URL "/?fr=fptb-i3752" and Mozilla Firefox will not boot, why?

    I'm trying to get to my browzer on Firefox and I get: INVALD URL "/?fr=fptb-i3752" and Mozilla Firefox will not boot, why?

    Try to reset the homepage, this might get rid of the support page:
    *[[How to set the home page]]

  • IPhoto 8.1.2(424) just will not quit.  Even after rebuilding library

    I am using iPhoto on a shared folder between two users. Somehow my iPhoto just will not quit. I tried Command option to start iPhoto to rebuild the library but it still did not work.
    the only way I can quit is to force quit it. Any help will be great. Thanks.

    Make sure the other user is not using the library at the same time. Create a test library, add a couple of photos in it, put in the same shared folder and try it.
    OT

  • Trying to downlord itune  my new laptop but it just will not download?

    trying to downlord itune  my new laptop but it just will not download?

    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.org/kb/Server+not+found
    *https://support.mozilla.org/kb/Firewalls
    See also:
    *http://kb.mozillazine.org/Browser_will_not_start_up

  • Just purchased iMac & itunes will not open why?

    I just purchased a new Imac and I tunes will not open when iphone or ipad is connected.  Why?

    Make sure your New Mac is authorised...
    Open iTunes and from the Menu Bar select Store...
    From the Store menu, choose Authorize This Computer. (In earlier versions of iTunes, access this option from the Advanced menu).
    When prompted, enter your Apple ID and password, then click Authorize.
    See Here for full details...
    About authorization and deauthorization
    Have you Transfered your iTunes Library from your Old computer to your New Mac...?
    iTunes: How to move your music to a new computer
    Or...
    Copy your ENTIRE iTunes FOLDER to an External Drive... and then from the External Drive to your New Computer..
    Backup iTunes to an External Drive
    http://support.apple.com/kb/HT1751
    An Added Bonus is that you will have a Backup of iTunes.

  • 1.4 - Important sites will not work & why are the AIM / Facebook contacts integrated with my phone contacts?

    Two issues I am having with my phone.
    1 - Before upgrading to the 1.4 software patch, I was able to visit some sites that I use regularly, one being www.hotschedules.com. I bartend and use my phone to look at my weekly schedule but now it will not work. Just to test it, I used a buddies phone who had not upgraded to 1.4 and the site opened JUST FINE!
    2 - I want to use facebook and AIM on my phone but for some (stupid?) reason, ALL of my facebook and aim contacts get listed in the SAME LIST as my phone contacts. I do NOT want to scroll through hundreds of contacts to find someone. Yes I know there are shortcuts but why even do this in the first place?

    Hello eculley and welcome to the forums;
    I attempted the website you mentioned, and it loaded fine on 1.4.1.1 on my Sprint Pre. We did identify some issues with websites on 1.4, and this should be resolved with 1.4.1. I know 1.4.1 is not available for Verizon yet, however it should be available soon.
    As for Facebook contacts, they show in the Synergy contact list by design, so that you can see all of your contacts in one master list. If you do not want those contacts showing in your Contacts app, you can open Preferences & Accounts for contacts and remove any account you don't want to see contacts for.
    Hope this helps!
    TreoAide

Maybe you are looking for

  • Re-delivering via iBooks Author

    Hey guys. Quick question. I uploaded my first book, and was met with only two tickets regarding its content. Easy to fix, but I had to update the metadata (title), cover art, and book assets. I followed the instructions found here: http://support.app

  • CallableStatement UnsatisfiedLinkError

    I am making a function call to an oracle package/function that is returning a value. I am getting at the execute statement an UnsatisfiedLinkError on oracle.jdbc.oci8.OCIDBAccess.copy_value_from_binds(Native Method). I am using an 8i driver for Oracl

  • How to make a menu for HD content (not BD)

    I am a newbie on this forum and I am not sure where to post: I am a middle-aged woman with blond (grey) hair (**** happens) BUT I have been 'playing around' with computers since 1977. I have been editing video and audio since the 90's and mainly as a

  • Need info regarding 11g OCA.

    Hi I am a 9i OCA. How can I upgrade to 11g OCA ? Please guide in this regard.

  • Business Catalyst not Recognizing Dreamweaver

    I am setting up a new site on Business Catalyst using the beta of Adobe Dreamweaver CS6. All seemed to be working fine until last week. I brought up a page and went to access the Business Catalyst widgets in the BC panel. Instead, the BC panel gave m