Results 1 to 2 of 2
  1. #1
    TyCox94's Avatar
    TyCox94 is offline Member
    Join Date
    Sep 2011
    Posts
    38
    Rep Power
    0

    Default Stopping a looped method

    I have a button that I want to "toggle". The button activates a looping method. I want to be able to stop the loop with the same button, or a different button if needed. For some reason the button freezes?

    Java Code:
    public void start() {
            //some code();
            start();
        }
    Last edited by TyCox94; 09-26-2011 at 12:45 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,604
    Rep Power
    5

    Default Re: Stopping a looped method

    Swing is single threaded: start a long task within the single thread (eg the EDT) - eg with the click of a button through an ActionListener - and it will lock up the user interface until said task is complete. Use a Thread, SwingWorker, or SwingTimer to do the work in parallel to the EDT. Google these for more information on each.

Similar Threads

  1. stopping the thread
    By kailash in forum Threads and Synchronization
    Replies: 2
    Last Post: 02-06-2011, 01:21 PM
  2. Stopping threads
    By phil128 in forum Threads and Synchronization
    Replies: 2
    Last Post: 01-06-2011, 03:38 PM
  3. Stopping a thread
    By userj2ee in forum New To Java
    Replies: 3
    Last Post: 08-13-2010, 07:57 PM
  4. Stopping a .swf with java
    By ercarls in forum New To Java
    Replies: 2
    Last Post: 04-14-2010, 06:33 PM
  5. Looped repaint of display area
    By gligor_kot in forum Java 2D
    Replies: 3
    Last Post: 07-28-2009, 12:53 PM

Posting Permissions

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