Applet Freezes

When I run my applet it freezes, can anyone see what's wrong?
public void paint(Graphics g)
  g.drawImage(airplane, planesXPos, planesYPos, PLANE_WIDTH,                                 PLANE_HEIGHT, this);
  g.drawString(numbers, textXPos, textYPos);
  planesXPos--;
  textXPos--;
public void actionPerformed(ActionEvent event)
  level = new Level();  
  if (event.getSource() == easy)
   level.setToEasy();
  else if (event.getSource() == medium)
   level.setToMedium();
  else
   level.setToHard();
  runGame();
  // True if the screen is clear, false otherwise.
public boolean isScreenClear()
  boolean flag = false;    
  if (textXPos < 0)
   flag = true;
  return flag;
public void runGame()
  number.ammendString();
  numbers = number.getAllNumbers();
  while (! isScreenClear())
   repaint();
}Thank You

Why isn't updating state good and why isn't it
working?Updating state is good. Updating state in your paint method is bad, because (1) you don't necessarily have control over when paint() is invoked, and (2) it's an operation about viewing and things like that shouldn't have side-effects. By "updating state", I'm referring to these lines:  planesXPos--;
  textXPos--; if I wasn't clear.
Also, the game will pause, once textPos is < 0. that
is when I want it to stop repainting.That's not what I meant. Think about how animation works. An image is displayed, held for a bit, then replaced with another image which has been updated slightly, which is then held for a bit, etc. Consider movies. A movie runs at 24 frames per second, so since each individual frame is a separate drawing (in practice, animated movies often "shoot twos" which means 12 fps; sometimes they "shoot fours", etc.) then each drawing is held up for 1/24 of a second.
Your code isn't doing that, so the only time delimiter between frames is the implicit one controlled by redraws updating state. The results are unpredictable and probably won't look good.
A more typical animation/game loop looks more like this (in psuedo-code):
while (should_continue_to_animate) {
  update_state();
  repaint();
  sleep();  // Thread.sleep() or using a Timer
}There are other variations, but we'll worry about those later...

Similar Messages

  • Fix Applet Freezing for once and for all!

    You know its really surprising to me that this applet freezing bug isn't being seriously worked on by Sun or Microsoft or whoever is responsible. I have been plagued by this for 3 years now and there is no improvement.
    Everybody who plays online games on the internet knows of the notorious Java "freezing" problem (there are notes in the FAQ's of all the major gamesites: pogo, gamesville, bingo.com, bingoonline, etc), and it is commonly understood that it is caused by sound conflicts.
    This is a problem that really irritates hundreds of thousands of people every day, and is doing a lot to give Java a very bad name. If I tell prospective customers that my games are Java based they wince and tell me that they would prefer Flash front-ends because of this freezing problem.
    I know what some of you are thinking: Q: Why not loop a silent sound clip in the background? A: That only results in a 70% improvement in the freezing, but when people play casino games nonstop they still freeze at least once every half hour. Q: Freezing is due to bad programming A: Thats a crock. I have yet to hear about a single online applet with sound that doesn't suffer from this problem. Turn off the sound, and the problem goes away completely.
    So seriously, if any of you are as sick of this as I am, please vote for this bug in the bug parade:
    http://developer.java.sun.com/developer/bugParade/bugs/4394767.html
    Chuck

    Hi there,
    As I mentioned in my message the only workaround that marginally improves the situation is to loop a silent sound clip while the program is running. I'm not sure if this problem occurs with the plugin or even java 1.2- it doesnt make much difference to me because I still have to write my games in java 1.1 so that they can be used on most browsers without requiring the players to install special software or plug-ins. I do recall seeing a "patch" on the microsoft site last november that was supposed to fix this problem, but obviously it didn't..

  • Applet freezes requesting which cert should use for a SSL connection

    Hello everyone,
    I have a strange problem. Applet freezes when it request which certificate should it use to connect to the server through a SSL connection. It works fine if it does not show the "choose certificate" window.
    I can not give more clues, but I am quite desperated and I hope you can help.

    Hello everyone,
    I have a strange problem. Applet freezes when it request which certificate should it use to connect to the server through a SSL connection. It works fine if it does not show the "choose certificate" window.
    I can not give more clues, but I am quite desperated and I hope you can help.

  • Java applet freezes while loading on Firefox on Mac OS 10.9

    I am using Mac OS 10.9.4 with Firefox 32 and Java 7 update 67. The java applet freezes while loading for the first time. On double clicking, it loads successfully. Once the applet gets loaded then it loads successfully until the web-page is refreshed or cache is cleared. I don't see any error message or any errors in the java console logs. Any help on this issue, apart from the double click work around? Any permanent solution?

    This delay can also happen when Java has been unloaded from memory and needs to be reloaded from disk and (re)initialized.
    You may be tight on available (free) memory if this happens all the time.

  • Applet freezes while Jar is loading

    Hi everyone,
    I have a fundamental question concerning the loading mechanism of an applets resources.
    The problem is as follows:
    I have two jars, the first containing all *.class files, the second (size: 10MB) containing only graphics and sounds.
    I start the applet with this code:
    <APPLET ARCHIVE="init.jar,resources.jar" HEIGHT="100" [...]>Of course the point is to have the small init.jar loaded fast an display a loading animation while the big file is beeing loaded in the background. Up to here everything works as expected. When i start the applet, the init.jar is loaded and displays a loading animation as long as i try to get a resource from the resource.jar.
    When I do that, my applet freezes while the big resource.jar file is beeing downloaded.
    This is how i access the resource in the resource.jar
    public void run() {
         while(/*some condition*/) {
              // this is the line which blocks until whole jar is downloaded
              java.io.InputStream input = this.getClass().getClassLoader().getResourceAsStream(/*resource String*/);
              // use input to load resource
    }The freeze happens only upon the first time the while-loop runs, after that the resource.jar is chached and access is almost instant.
    Now the concrete problem is, that the applet freezed in all its threads while the jar is beeing downloaded. I NEED to display an idle animation while this is done.
    Has anyone any suggestion how i can avoid the complete freeze?
    I have already concidered to load the resources without specifing the jar in the HTML-ARCHIVE-Tag, this works becouse of the codebase i can load the ressources from, but the problem is, that these resources have a large overhead from the server to the client until i can use them in the program.
    Also it is no option to load them all on startup in another backgound thread (which would slove the freeze problem, i tried it), becouse i have to dynamically load and unload these resources to avoid OutOfMemory-Errors. Reloading them brings the overhead-Problem up again.
    Only when i specify the 2nd jar in the ARCHIEVE-Tag i have direct access to the browsers chache without wasting memory when holding references to all resources.
    After all every loading and stuff works, there are no errors in the programm only this strange behaviour. I Also tried it with different VMs, on different OS, and different Browser, all the same.
    I would be glad if someone could give me a hint on this, i've been searching for days now, even tried to analyse the Classoader sources but ended up in sun's native calls...
    Thank you in advance
    - Loddi

    I've been encountering the same problem and I think I've figured out the reason behind it and how to solve it.
    It appears that the class loader can only ever load one resource at a time. Once you've forced it to start downloading resources.jar, it can't load any classes until that download has finished, not even classes that are part of the Java API. In your case I believe the solution would be to display one loop of your idle animation before you start loading resources.jar, to make sure that everything the idle animation needs has already been loaded by the class loader.

  • Applet freezes while downloading a ressource jar!

    Hi everyone,
    I have a fundamental question concerning the loading mechanism of an applets resources.
    The problem is as follows:
    I have two jars, the first containing all *.class files, the second (size: 10MB) containing only graphics and sounds.
    I start the applet with this code:
    <APPLET ARCHIVE="init.jar,resources.jar" HEIGHT="100" [...]>Of course the point is to have the small init.jar loaded fast an display a loading animation while the big file is beeing loaded in the background. Up to here everything works as expected. When i start the applet, the init.jar is loaded and displays a loading animation as long as i try to get a resource from the resource.jar.
    When I do that, my applet freezes while the big resource.jar file is beeing downloaded.
    This is how i access the resource in the resource.jar
    public void run() {
         while(/*some condition*/) {
              // this is the line which blocks until whole jar is downloaded
              java.io.InputStream input = this.getClass().getClassLoader().getResourceAsStream(/*resource String*/);
              // use input to load resource
    }The freeze happens only upon the first time the while-loop runs, after that the resource.jar is chached and access is almost instant.
    Now the concrete problem is, that the applet freezed in all its threads while the jar is beeing downloaded. I NEED to display an idle animation while this is done.
    Has anyone any suggestion how i can avoid the complete freeze?
    I have already concidered to load the resources without specifing the jar in the HTML-ARCHIVE-Tag, this works becouse of the codebase i can load the ressources from, but the problem is, that these resources have a large overhead from the server to the client until i can use them in the program.
    Also it is no option to load them all on startup in another backgound thread (which would slove the freeze problem, i tried it), becouse i have to dynamically load and unload these resources to avoid OutOfMemory-Errors. Reloading them brings the overhead-Problem up again.
    Only when i specify the 2nd jar in the ARCHIEVE-Tag i have direct access to the browsers chache without wasting memory when holding references to all resources.
    After all every loading and stuff works, there are no errors in the programm only this strange behaviour. I Also tried it with different VMs, on different OS, and different Browser, all the same.
    I would be glad if someone could give me a hint on this, i've been searching for days now, even tried to analyse the Classoader sources but ended up in sun's native calls...
    Thank you in advance
    - Loddi

    Multiple post
    http://forum.java.sun.com/thread.jspa?threadID=5204797&messageID=9818313#9818313

  • Image array applet freezes

    I'm using a modified version of Romain Guy's music shelf (http://www.curious-creature.org/2005/07/09/a-music-shelf-in-java2d/), using it as an applet in an extension for a mozilla based media player.
    In order to allow decent performance I'm using a proxy pattern, so the images are not actually loaded until they're needed. All the proxies are stored in a simply java array at startup. When more than 100 of the proxies have loaded their image, the whole thing slows down, and when 113 (exactly and always) have loaded, the applet freezes completely.
    Anyone got any idea why this might be happening?? There's plenty of memory left and the applet is run localy so it shouldn't be security probem either.

    Nevermind..... a classic case of RTFM. I might have enough memory, but java only has 64mb....

  • Java applet freeze completly browser

    Hi there
    Ive created a smalle board game in an ASP / Javascript page. The game is multiplayer and i connect everybody via an java applet to a java server.
    Well, it look like this :
    ASP / Javascript --> Applet --> JavaServer --> Applet --> ASP / javascript
    The game is just fine and completly functionnal. The problem is : We just brought in some video for the players who have Webcams. And those video freeze when the applet is waiting a response from the server. Is there anyway that the applet does not freeze the whole browser so that the video continu playing even if the game is waiting?
    the main window contain 2 sections, �video & chat� and the game. The game containt a few frames with one of them containing the applet. In the java applet, im using BufferedReader and PrintWriter with AppletSocket to communicate with the server.
    Im not sure if i have made myself clear, if not, tell me, ill try to make it clearer.
    Thanks in advance
    Marc
    P.S. sorry for my english

    There maybe some code will help most of you to understand better my problem.
    Here's the function in my asp pages that wait for the applet response.
    function AttendreReponse()
         AppletConnect.Recevoir();
         GererRecevoir();
    }The javascript function 'GererRecevoir()' get the code that was sent by the server, analyse it and then, do run the proper function so the game can go on normally..
    And here's the java function 'Recevoir()' in the applet
    public void Recevoir()
      // String received from the server
      String fromServer = "";
      this.paramTransaction = "";
      this.codeTransaction ="";
      try{
        // Reads the string received
        fromServer = this.in.readLine();
        if(fromServer != null)
          this.codeTransaction = fromServer.substring(0,2);
          if(fromServer.length() > 2){
            this.paramTransaction = fromServer.substring(2); //retrieve the 2 next ^^
      // Applet dosent receive anything anymore from the server
      catch (IOException e){
        System.out.println("Le serveur n'est plus en fonction");
        System.exit(1);
    }So the main problem is that the applet freeze the whole window then ge gets to : fromServer = this.in.readLine();
    He wait until he get a response or untill he timeout.
    What I would like, is that the applet does not freeze the whole window while waiting since videoconference, chatting and sound arent very usefull if you can use them 3/4 of the time.
    I hope this helped you to understand a little bit more.
    Thanks again
    Marc

  • Applet freezes (seemingly) randomly upon certain actions

    Hello all,
    I am developing a signed java applet for my company in which the user can hit multiple HTML buttons, and those buttons trigger javascript which in turn signals the applet to perform some task. I can't post the source code unfortunately, but the main gist is that the following buttons are available: Upload Files, Preview File, Edit File, Copy To USB, Delete, and Exit.
    This applet is used only on a closed system (i.e. we can trust our users 100%), so everything is handled through AccessController.doPriveleged calls, so as to give full access to the actions called from the javascript.
    To clarify each of the actions:
    (We deal mostly with ppt/pps)
    Upload Files - opens up a JFileChooser window for the user to select multiple files. Upon hitting OK, the files are sent to a server for permanent storage, and copied to a desktop folder for temporary storage.
    Preview File - Converts a ppt to pps (if needed), and launches it using the Desktop.open() call.
    Edit File - Converts file from pps to ppt (if needed) and calls Desktop.open().
    Copy To USB - opens a JFileChooser for the user to select a USB stick directory, and copies all files from the desktop to it.
    Delete - Displays a confirmation window, and upon hitting OK deletes the file from the client and server.
    Exit - Confirms with the user, and upon hitting OK, re-uploads any edited files to the server and navigates away from the page.
    Most of these actions are handled through threads. So every time a button is hit, a new thread is spawned. The threads go away once the action is performed in full .. i.e. when all files are uploaded, or a file is launched.
    Everything works like a charm, except (seemingly) randomly, when hitting the Upload, Copy, or Delete button the applet will freeze. I have many System.err.println statements throughout the entire application and it seems as though the applet freezes very early on in performing action. Namely, the last debug statement I see before the console freezes is usually "Perfoming action ('action name')" or "Dispatching to privileged thread". The first statement happens right after the doPrivileged call, and the second statement happens right before the call.
    There are no exceptions or anything displayed in the java console. This only happens on those 3 actions. The only thing I think they have in common is that they each show a JOptionPane/JFileChooser. The other actions don't. While the applet appears frozen, I noticed I could still launch files for previewing and editing, but no debug output is produced where it should be.
    Like I said, this appears random, but happens often. I can sit there and hit preview/edit over and over again for 10 mins and it will never freeze up. However, if I sit there hitting Upload/Copy/Delete over and over, it will normally freeze after 1-10 times (usually closer to 1-5).
    I know there is limited help you guys can give without seeing the source code, but I was wondering if anything pops out as a possible cause.
    Thanks for reading.
    Bryan

    Thanks for the response.
    I converted to JApplet, and am still noticing this behavior.
    Also, this freezing happens regardless of if I actually upload a file or not. What I am doing is just clicking Upload, then cancel, Upload, then cancel, and repeating a few times until it locks up. Same with the Copy button. I don't actually hit OK to copy, just keep hitting cancel. So each time I hit the button the following should be happening:
    Button is hit
    Javascript function is called
    Javascript calls java function dispatchAction.
    java function dispatchAction performs a doPrivileged, which inside the PrivilegedAction calls performAction
    performAction creates a Worker class, which is a custom class I made that implements Runnable. The reason for this is I had to be able to pass an external variable into the thread, and wasn't able to with a normal Runnable.
    the Worker class is run as a new thread, and inside it calls a function that creates the JFileChooser
    That's about it. I have been over the code a few times and find this very peculiar, because VERY little happens when the Upload/Copy/Delete buttons are clicked, then cancelled. The only thing I can see is an issue with calling too many doPrivilege or something, or too many threads .. no idea.
    Any other ideas?

  • Java applet freezing over internet but not on harddrive

    Hi,
    So I have this java applet game, When running the webpage with it off my harddrive the applet runs fine. However, after putting my website on my server after leaving the second menu, into game mode, the java applet freezes. I don't think it's a code issue since it doesn't freeze when running off my harddrive, or when running in netbeans. What would cause this????
    hiraganakatakana.tantonj.com --- that's the url for the game, you'll see how it freezes after choosing one of the second options.

    tantonj wrote:
    ..So I have this java applet game, When running the webpage with it off my harddrive the applet runs fine. However, after putting my website on my server after leaving the second menu, into game mode, the java applet freezes. I don't think it's a code issue since it doesn't freeze when running off my harddrive, or when running in netbeans. You are really new to applets, aren't you? I don't care where you are running the applet from, but how it is being run. Is it being run in appletviewer, or a browser, or something else?
    ..What would cause this????Please fix that sticky '?' key.
    hiraganakatakana.tantonj.com
    java.lang.NoClassDefFoundError: runApp (wrong name: hiraganakatakana/runApp)
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
           ....

  • Keyboard layout indicator applet freezes in GNOME

    Hi all!
    Keyboard layout indicator applet freezes in GNOME. This means that I'm not able to switch layouts by clicking on applet and applet doesn't show current keyboard layout The only way to solve this - delete applet from The Panel and place it again.
    This strange behaviour began after latest GNOME updates.
    How can I solve this "correctly"?

    Problem dissappeared with this in xorg.conf:
        Option "XkbRules"    "xorg"
        Option "XkbModel"    "pc105"
        Option "XkbLayout"    "us,ru"
        Option "XkbVariant"    ",winkeys"
        Option "XkbOptions"    "grp:alt_shift_toggle"
    Seems that GNOME doesn't like "ru(winkeys)" in "XkbLayout"

  • Modality popped - applet freeze

    Im trying to fix an applet freeze problem. It occurs randomly and it causes the applet to have a bunch of blanked out components and the applet freezes completely. In the trace file, it always does a Modality popped/pushed before the freeze happens. The users are using Java 1.5.0_04 and have Intel video cards with upto date drivers. DirectDraw is also disabled. Any sort of insight is appreciated!

    Also, im compiling with the following flags:
    -source 1.3 -target 1.1

  • Disco App Server high CPU usage, Disco Applet freezes, tuning possible?

    Hi again,
    so I am facing again a dramatic performance issue with our Discoverer.
    I have a cross-table report with ten page items, one datapoint, a percentage calculation and a total.
    After querying the data from the DB, building the report (calculating total and percentages) takes 50 seconds, Disco Applet is freezed, App Server shows high CPU load (one core about 60%, other three cores about 20%). The report fetches 5600 rows, which is quite nothing.
    Disco Version: 10.1.2.54.25 (CPU IV).
    Are there any parameters / settings on the application server to improve the performance at this place?
    Thanks in advance,
    Christian

    I found the solution for this special problem: the total in the report was the cause. Without it, the report reacts as I expect it.
    Nevertheless, other reports (approx. 300.000 rows of data in a crosstab) with four page items also cause this high CPU load on the AS and freeze Disco for some half a minute. Our costumers do complain about this as it always seems that Disco hung up.
    Any suggestions on how to tune the AS?
    Regards,
    Christian

  • Problems with java applets freezing.

    Okay, this is an extemely rare java problem (from what I know), and I have worked for months to fix it and nothing has worked so far.
    This is my problem: Whenever I use java applets, the screen freezes (still able to move mouse around) for about 10-20 seconds about twice a minute to once in ten minutes. This can make me very angry if I am in the middle of a game. I am POSITIVE it isn't my internet, I have Cable internet, one of the fastest. And after it is done freezing the applet runs perfectly, until it freezes again.
    PLEASE HELP ME! Thanks in advance, Zach.

    I decided to take a look, but the Bridge program requires a signup. Not interested, but the free Poppit game plays fine as a guest on my machine on both Safari 3.1 and FireFox 3.0b4.
    With FireFox I'm running AdBlock Plus, which can create problems with some sites, but the games loaded and played.
    Based on this, I'd check the time of day you are trying to use their site and see if there are more problems with certain times.

  • Why cant i run my applet on JRE 1.6 but on JRE 1.5?

    Hello,
    I know this is a very basic problem, but i still cannot get a justified answer for this problem. Its like i have an applet which is compiled in JDk j2sdk1.4.2_16. Now when i try to run this applet on my IE under jre 1.5.* family on all the client machines it works fine. But when i switch to jre 1.6.* family, i see the applet being displayed, but i cannot perform any operations on it i no mouse clicks work and i cannot open any file menu or my jdialog boxes.
    Is it because of the incompatibilities in jre 1.6, but wont it be backward compatible to that older version applets can run on this new jre. My applet seems to be a simple applet,with only one exception that it has lot of jframes and jpanel in it.
    This problem is killing me ..
    Can someone point me towards where can i find what all changes are made in JRE 1.6 over JRE 1.5 so that atleast i can compare what is causing my applet freeze in JRE 1.6.
    i went through the release notes but cant find anything useful there.
    Please help.

    Sun ensures that newer versions of the JRE are backward compatible. Your applet should work under the newest JRE version. Have you tried running the applet in a different browser (e.g., Firefox) with JRE 1.6 to eliminate it being an IE issue?

Maybe you are looking for