Results 1 to 5 of 5
  1. #1
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default JApplet retains information after leaving page

    Hello I have a JApplet on a webpage. Everything works fine the first time I go to it in a session. If I go to a different page, and come back to it, there are issues. Even if I refresh the page, I have issues. They do not go away until I close the whole browser and reopen.

    The issue I am having is the last thing that was painted on the screen before leavign the page show up again next time you go to the page. I want to start fresh every time I go to the page again.

    Thanks!

  2. #2
    andyman99008 is offline Member
    Join Date
    Dec 2010
    Posts
    17
    Rep Power
    0

    Default

    Hello, The convention is to create threads in init(), start them in start(), and stop them in stop()...The start and stop methods are automatically called as you leave/enter the page.

  3. #3
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default

    Interesting. Do you have an example of this that I could look at?

  4. #4
    andyman99008 is offline Member
    Join Date
    Dec 2010
    Posts
    17
    Rep Power
    0

    Default

    Java Code:
    public class AppletName extends JApplet implements Runnable {
    
       Thread myThread= null;
    
    public void start() {
    
        if ( myThread== null ) {
    
            myThread= new Thread( this );
            myThread.start();
        }
    }
    
    public void stop() {
    
         if ( myThread!= null && myThread.isAlive() )
             myThread.stop();
    
        myThread= null;
    }
    public void run() {
    
        while ( myThread!= null ) {
    
            repaint();
    
            try {
    
                Thread.sleep(20);
    
            } catch ( InterruptedException e ) {
    
                // do nothing
    
            }
        }
    }
    }

    If you never used threads before I suggest you read up on them.
    Last edited by andyman99008; 12-20-2010 at 04:37 AM. Reason: code tags

  5. #5
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default

    Thanks again. I will try this when I get home from work today.

    My only concern is the while loop in run(). Is this good programming practice to do long running loop like this with the repating and sleeping?

Similar Threads

  1. Replies: 3
    Last Post: 03-03-2011, 05:59 PM
  2. Replies: 0
    Last Post: 05-19-2010, 10:44 PM
  3. JApplet on MAC
    By ld_pvl in forum Java Applets
    Replies: 0
    Last Post: 08-23-2009, 02:40 PM
  4. how to clear the session when leaving a page.
    By shivakumari in forum Java Servlet
    Replies: 3
    Last Post: 03-25-2009, 07:25 AM
  5. JFrame to JApplet or JApplet to JApplet
    By ramesh.8189 in forum AWT / Swing
    Replies: 13
    Last Post: 02-08-2009, 07:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •