Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Applet loop problem

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Applet loop problem

    hi, im a noob programmer but i understand something about java. I watched all the video tutorials about java gamimg, but now I want to convert the game into applet but i can't, specially because it doesn't support loops :S

    And if I use the method repaint() the FPS get too low...

     
       //Called when this applet is loaded into the browser.
     
       public void init() {
     
          addMouseListener(this);
          addMouseMotionListener(this);
          addMouseWheelListener(this);
          mess="press escape to exit";
          setForeground(Color.WHITE);
          loadImages();
     
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
     
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
     
                    public void run() {
     
                       startingTime=System.currentTimeMillis();
                      cumTime= startingTime;
     
                      timePassed = System.currentTimeMillis() - cumTime;
                         cumTime+=timePassed;
     
                         while(running){
                         update(timePassed);
                         updatePrisao( timePassed);
                         preso1.update(timePassed);
                         preso2.update(timePassed);
                         preso3.update(timePassed);
                         preso4.update(timePassed);
                          repaint();
     
     
                         try{
                            Thread.sleep(20);
                         }catch(Exception ex){}
     
                      }
                    }
                    }
     
     
     
                    );
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            }
     
       }

    i dont put the repaint becouse i dont now where i go put :S
    if i do a while using a boolean the applet crashes
    Last edited by bluecora; June 14th, 2012 at 08:52 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Applet loop problem

    That is waaay too much code to ask other people to read through for you, especially since you didn't really tell us what the actual problem is. Applets definitely do support loops.

    I suggest you narrow your problem down to an SSCCE that demonstrates what you're talking about in as few lines as possible.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applet loop problem

    i change code for small code, if you see the repaint in while its my problem, he crash.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Applet loop problem

    When it crashes, do you get an error? Why are you calling the sleep() method while on the EDT? That's a big no-no, and will cause your program to become unresponsive or laggy.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Applet loop problem

    I guess you didn't like the answers I already gave you? Looks like I'm just wasting my time trying to help you.

    This thread has been cross posted here:

    http://www.java-forums.org/java-applets/60693-help-java-applet-loop.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applet loop problem

    i dont read the rules, but i need to finish my applet but i cant becousa this error **** me
    Last edited by KevinWorkman; June 14th, 2012 at 12:53 PM. Reason: keep it PG, please

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Applet loop problem

    I've asked you questions that you haven't answered and told you why your program is probably not working, which you've ignored. If you don't have time to read the rules, create an SSCCE, or even respond to help you're receiving, why should other people take their time to help?

    I recommend you read the link in my signature on asking questions the smart way before you post again.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Another applet to program problem....
    By iZigZag in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 9th, 2012, 12:09 AM
  2. Problem Applet Error
    By mohsendeveloper in forum Java SE APIs
    Replies: 24
    Last Post: January 19th, 2012, 04:00 PM
  3. Applet problem with MouseEvent
    By smashX in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 10th, 2011, 03:24 PM
  4. Problem with my animation applet
    By cBlue in forum Java Applets
    Replies: 1
    Last Post: December 9th, 2009, 07:49 PM
  5. applet and JPS problem.... please help me
    By rockster14 in forum Java Applets
    Replies: 0
    Last Post: August 7th, 2009, 03:59 PM