Java - sleep in a for loop doesn't work (as desired)

Hey all,
I'm trying to get a draw animation when the mouse is released (after dragging an object to a set area on the screen) - hence I'm trying to do this via a for loop with a small sleep() delay. However it isn't working. The delay is there, but nothing changes until the end of the for loop and then you only see the final repaint() [i.e. instead of each iteration in the for loop]:
// This program is concerned with this and the mouseDragged methods
     public void mouseReleased(MouseEvent e)
          for( int c = 0; c < xButton.length; c++)
               if( xButton[c] >= xRandWeight && xButton[c] <= (xRandWeight+50) && yButton[c] >= yRandWeight && yButton[c] <= (yRandWeight+50) )
                    // Have an animation for the scales re-adjusting
                    if( c == 0 )
                         currWeight = (int)(scales.getWeight2());
                         desiredWeight = Integer.parseInt(b1.getLabel());
                         if( desiredWeight >= currWeight )
                              // More efficient than putting this subtraction straight into for loop
                              difference = desiredWeight - currWeight;
                              for( int count = 1 ; count <= difference ; count++ )
                                   scales.setWeight2(currWeight+count);
                                   repaint();
                                   try
                                        Thread.currentThread().sleep(100);
                                   catch (InterruptedException in)
                                        in.printStackTrace();
                         else
                              difference = currWeight - desiredWeight;
                              for( int count = 1 ; count <= difference ; count++ )
                                   scales.setWeight2(currWeight-count);
                                   repaint();
     }Any ideas on how to fix this/meet the goal would be greatly appreciated :)
Thanks,
Tristan Perry
Edited by: TristanPerry on Nov 16, 2008 12:36 PM

My program isn't being written in SWINGFirst, it's Swing, not SWING. It's not an acronym.
Perhaps you would like to tell us which windowing toolkit you are using, so that you can get better responses. Or is that a closely guarded secret? <sarcasm/>
I'm very new to JavaSo ditch the GUI stuff and get a foundation first.
db

Similar Messages

  • Using CONNECT BY LEVEL with For Loop Doesn't Work

    The procedure listed below inserts only one record in table whereas i need 10 records to be inserted in table.
    this is just a test procedure..
    CREATE OR REPLACE PROCEDURE P_TEST
    AS
    BEGIN
    FOR I IN (SELECT LEVEL num FROM dual CONNECT BY LEVEL <= 10)
    LOOP
    INSERT INTO TEMP_VMS VALUES(I.num);
    END LOOP;
    END;
    END;
    /

    Salim Chelabi  wrote:
    Or with 9ir2
    INSERT INTO TEMP_VMS
    SELECT COLUMN_VALUE
    FROM TABLE (SYS.dbms_debug_vc2coll (24, 34, 25));
    SELECT *
    FROM TABLE (SYS.dbms_debug_vc2coll (24, 34, 25));
    COLUMN_VALUE                                                                   
    24                                                                             
    34                                                                             
    25                                                                             
    3 rows selected.
    http://laurentschneider.com/wordpress/2007/12/predefined-collections.html
    That doesn't split strings...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'a,b,c,d,e' str from dual)
      2  --
      3  SELECT *
      4*   FROM t, TABLE (SYS.dbms_debug_vc2coll (t.str))
    SQL> /
    STR
    COLUMN_VALUE
    a,b,c,d,e
    a,b,c,d,e... it only defines a table of values

  • I cannot access my old email address anymore, however I have used it for my apple ID and now I want to delete it because the account has never been verified in the first place so my password for it doesn't work. What do I do?

    I cannot access my old email address anymore, however I have used it for my apple ID and now I want to delete it because the account has never been verified in the first place so my password for it doesn't work. So when I want to download apps I have to sign in with apple id but I can't so I made a new one, However I can't seem to be able to delete the old one. What do I do?

    You can't merge Apple IDs.  You also can't cancel (delete) and existing ID, you can only choose to stop using it.
    If your old ID was compromised and you can no longer access it, you'll have to contact Apple for assistance.  Go to https://expresslane.apple.com ; click 'See all products and services' at the bottom of the page. In the next page click 'More Products and Services, then 'Apple ID'. In the next page select 'Other Apple ID Topics' then then 'Apple ID account Security’.

  • I have an Iphone 3GS and the app for Facebook doesn't work anymore...

    I have an Iphone 3GS and the app for Facebook doesn't work anymore since last update made yesterday.
    How can I restore it without the last update?
    Or, what can I do to have the Facebook back again on my mobile?
    Thank you for your help.

    Hi Ricoco,
    I too had exact issue what you were experienced, then I went to Apple autorised service center and submitted my earpods, their it worked with all versions of Apple iphones, but it didn't worked on my 3gs. The service technician suggested for OS  upgrade.Then I came home and I took the backup and upgraded 5.1 to 6.1 as he suggested, also it didn't worked. I was totally frustated and suddenly I got an idea!. What a funny thing here is, a safety pin resolved my issue, I took out all dust which was there in the jack hole. Then I check my earpods, it was amazing you know..MY EAR PODS WORKED!.
    If you still have this issue, I hope this will help you.
    Umesh

  • Voice command for Contacts doesn't work after a re...

    Voice command for Contacts doesn't work after a reboot or a contacts restore.
    Steps to reproduce:
    1. Backup contacts. Open Files > Backup & Restore > Select Contact for Backup Contents and select Back up now.
    2. Edit/save a contact, press and hold the call button, speak contacts name. The voice recognition works fine.
    3. Restore contacts. Open Files > Backup & Restore > Select Contact for Backup Contents and select Restore.
    4. Reboot phone when prompted.
    5. Press and hold the call button, speak contacts name. The voice recognition does not work.
    Work around:
    Edit and save each contact.
    Additional Information:
    Social integration with contacts also does not work after a reboot. The facebook icon and "See what xxx is up to on Facebook" is not displayed. The same work around "Edit and save each contact" also applies. This occurs using the Nokia N8 and Nokia 808 Pureview.

    Nancy2015 wrote:
    I have my phone paired with my car, I can do everything except it does not recognize any of my contact names. If I try say a contact name, it says "not recognized" but if I say the contacts phone number, the name pops up onthe display in my car.
    Has anyone had this issue, is there a setting I am missing in my phone?
    Hello, 
    This is not necessarily and issue with the phone. It could also be an issue with the car`s bluetooth software that is only limited to some functions like reading your contacts list, last calls, missed calls, etc. which is most likely the basic 2.0 version. 
    The Z30 has the 4.0 version that has a lot more communication capability but if the car`s bluetooth its a lower version, then you will not be able to take full advantage of it unless you upgrade the bluetooth software in your car. Call your dealer and inquire about the bluetooth software upgrade in your car   

  • Quicktime for windows doesn't work, wont let me uninstall or update.Help!

    Quicktime for windows doesn't work, won't let me uninstall (tells me fatal errro) or update (tells me it encountered an error on installation). Help!I am running Windows XP on an Intel pentium PC. Any ideas? Dvora

    When you get this fatal error uninstalling, try a full removal of iTunes and related programs with an installer clean up of any that do not uninstall cleanly:
    Here is a method:
    Download a fresh copy of iTunes and the stand alone version of Quicktime (the one without iTunes)
    http://www.apple.com/quicktime/download/win.html
    http://www.apple.com/itunes/download/
    Download and install Microsoft Installer cleanup utility, there are instructions on the page as well as the download. Note that what you download is the installer not the program – you have to run it to install the program.
    To run the program – All Programs>>Windows Install Cleanup
    http://support.microsoft.com/kb/290301/
    Now use the following method to remove iTunes and its components:
    XP
    http://support.apple.com/kb/HT1925
    Vista
    http://support.apple.com/kb/HT1923
    *If you hit a problem with one of the uninstalls don't worry*, carry on with the deleting of files and folders as directed in the method.
    When you get to deleting Quicktime files in the system32 folder as advised in the method, you can delete any file or folder with Quicktime in the name.
    Restart your PC.
    Run the Microsoft Installer Cleanup Utility. (Start > All Programs > Windows Install Clean Up)
    Remove any references you find to the programs you removed - strictly speaking you only need to worry about those programs where the uninstall failed.
    If you don’t see an entry for one of the programs that did not uninstall, look out for blank entries or numeric entries that look like version numbers e.g. 7.x for Quicktime or 1.x for Bonjour.
    restart your PC
    Install the stand alone Quicktime and check that it works.
    If it does, install iTunes.

  • Textvariable with replacement path for 0CALMONTH doesn't work ...

    Hello expert,
    we have done release upgrade BW 7.01 -> BW 7.3 SPS 04. While checking queries I found out that textvariables with replacementpath for 0CALMONTH doesn't work anymore. In the report I only see the variable name like ZVARXYZ01 but want to see something like 'JAN 2011'.
    As far as I understand 0CALMONTH don't need a texttable. Texts can be found in table T247. I checked the table and all values looks fine.
    Any Idea where the problem is or how I can analyze it?
    Thank you in advance,
    Peter

    Hi Peter
    Please check this link, especially this note for text variable problems after upgrade to 7.3
    Let us know if it helps.
    Think of giving points.
    Regards
    PC

  • How can I make a Java program pyramid using for loops??

    Hi guys, so I'm stuck with my program here... I don't know how to make it work, and i've been trying really hard.. So now i give up and need some guidance.. Please help me here.
    Your job in this assignment is to write programs to solve each of these six problems.
    1. Write a GraphicsProgram subclass that draws a pyramid consisting of bricks
    arranged in horizontal rows, so that the number of bricks in each row decreases by
    one as you move up the pyramid, as shown in the following sample run:
    The pyramid should be centered at the bottom of the window and should use
    constants for the following parameters:
    BRICK_WIDTH The width of each brick (30 pixels)
    BRICK_HEIGHT The height of each brick (12 pixels)
    BRICKS_IN_BASE The number of bricks in the base (14)
    The numbers in parentheses show the values for this diagram, but you must be able
    to change those values in your program.
    * File: Pyramid.java
    * Name:
    * Section Leader:
    * This file is the starter file for the Pyramid problem.
    * It includes definitions of the constants that match the
    * sample run in the assignment, but you should make sure
    * that changing these values causes the generated display
    * to change accordingly.
    import acm.graphics.*;
    import acm.program.*;
    import java.awt.*;
    public class Pyramid extends GraphicsProgram {
    /** Width of each brick in pixels */
         private static final int BRICK_WIDTH = 30;
    /** Width of each brick in pixels */
         private static final int BRICK_HEIGHT = 12;
    /** Number of bricks in the base of the pyramid */
         private static final int BRICKS_IN_BASE = 14;
         public void run() {     
    }That's my problem.

    yo, so i figure out my for loop. my code is very very very very ugly, so dont laugh i know its ugly! just wanna ask for some tips
    public void run() {
              int initBrick = 30;
              int initPlacement = (getWidth() - BRICK_WIDTH) / 2;
              for (int i = 0; i < initBrick; i += 30)
                   int initX = i;
                   int x = initX + initPlacement;
                   GRect brick = new GRect(x, 0, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 60; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 15;
                   int y = 12;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 90; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 30;
                   int y = 24;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 120; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 45;
                   int y = 36;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 150; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 60;
                   int y = 48;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 180; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 75;
                   int y = 60;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 210; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 90;
                   int y = 72;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 240; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 105;
                   int y = 84;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 270; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 120;
                   int y = 96;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 300; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 135;
                   int y = 108;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 330; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 150;
                   int y = 120;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 360; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 165;
                   int y = 132;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 390; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 180;
                   int y = 144;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 420; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 195;
                   int y = 156;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
         }So yeah, it's very ugly. not general. BUT now; I know the logic of the program..
    I need to change 3 variables here.
    the Y var, the X variable, and the size of the loop test..
    so I need to make a one compact for loop that will change those 3 for every time the loop finish, or for every row the variable will change...
    Ill try to think again, ill head to the balcony, and squeeze my brain. YEAH it took me this long to figure this out, anyway im a noob YET. But i was working a while ago.
    ANYWAY, leave some tips please.. I NEED TIPS NOT SOLUTION

  • Count(*) in the loop doesn't work and I really don't know why...

    Hello,
    I can't figure out why the following doesn't work. I cannot debug for I do not have privileges on this server.
    The execution always fails on bolded line. If I substitute the variable with the table name itself it works. The variable is properly populated in each of the iterations as I can see it by using dbms_output package. The small but may be important detail may be I am connected as user A but the tables are in the schema B. However I can list the tables and their columns in all_tab_cols view and there are synonyms made in my schema which allow me to access the B tables without prefixing them.
    I get the error:
    Error report:
    ORA-00900: invalid SQL statement
    ORA-06512: at line 26
    00900. 00000 - "invalid SQL statement"
    *Cause:   
    *Action:
    I ran out of ideas and I do not have access to any of the Oracle instance to be able to debug right now.
    Variable type for v_tables is wrong? I do not have some magic privilege to use execute immediate with variable?
    Oracle server has a bad day today?
    The crap is 11.1.0.7 if it has anything to do with my problem.
    Please help if you can.
    Grzegorz
    declare
    v_number number := 646989;
    v_current_table nvarchar2(50);
    v_itemno number;
    type t is table of nvarchar2(50);
    v_tables t;
    begin
    dbms_output.put_line('Working...');
    select table_name bulk collect into v_tables from all_tab_cols where column_name = 'ITEMNO' order by table_name;
    for i in 1 .. v_tables.count loop
    dbms_output.put_line('Number: ' || i);
    v_current_table := v_tables(i);
    <b>execute immediate 'select count(*) from ' || v_current_table || ' where itemno = :a' into v_itemno using v_number;</b>
    if (v_itemno > 0) then
    dbms_output.put_line('Current table contains specific ITEMNO: ' || v_current_table);
    end if;
    end loop;
    end;

    In SQL Plus run this and see what SQL is your code returning. Then execute the SQL individually.
    set serveroutput on
    declare
         v_number number := 646989;
         v_current_table nvarchar2(50);
         v_itemno number;
         type t is table of nvarchar2(50);
         v_tables t;
         lSqlString varchar2(20000);
    begin
         select table_name
           bulk collect into v_tables
           from all_tab_cols
          where column_name = 'ITEMNO'
          order by table_name;
         for i in 1 .. v_tables.count loop
              v_current_table := v_tables(i);
              lSqlString := 'select count(*) from ' || v_current_table || ' where itemno = :a';
              dbms_output.put_line(lSqlString);
              --execute immediate  lSqlString into v_itemno using v_number;
         end loop;
    end;

  • Recomendations for you doesn't work

    quick link on main page of iTunes doesn't work.  I've tried everything and I can't get the link to work.  It worked fine for years and then it slowly stopped sending "Recommendations for you"  would time out and I would remain on main iTunes web page.

    Yes, it still occurs when logged in as a different user. Since my posting earlier this morning, I've noticed that when I type the delete key, the end bracket appears and continues to repeat until I press the space bar. I'm wondering if it's a virus. A colleague at work says that when his macbook is left on for too long, sometimes he will type one command and the macbook will do another. I have had the computer on or in sleep mode nonstop since Sunday morning. Is it possible that it's an over-use issue or possibly some kind of mac virus? The only app I downloaded from the web was a youtube downloader/mp3 converter.
    My main goal would be to reset all system commands to normal - if there's an easy way to do this.
    Thanks for asking.

  • Probook 4535s-sleep pressing the power button doesn't work

    Does this laptop can go to sleep via pressing the power button? I have these power settings but it doesn't work for me.  The button just turn off the laptop...

    freekarol,
    Welcome to the HP Forum!
    You can control what happens when you close the lid, press the power button, and other "power related" settings:
    Control Panel < icon view > Power Options >>
    Choose what the Power buttons do
    and
    Choose what closing the lid does
    Happy Computing!
    Click the Kudos Star!
    It is a great “Thank You” for the HP Experts who are here to help!
    Kind Regards,
    Dragon-Fur

  • FOR LOOP EXCEPTION not working !!! please help

    Hi,
    Why is the NO_DATA_FOUND execption not getting executed. ????
    Hereis the code....
    CURSOR newreccur IS
    SELECT * from emp_table;
    BEGIN
    v_file_handle := UTL_FILE.FOPEN('out','new.dat','W');
    BEGIN
    FOR emp_rec IN newreccur LOOP
    -- Write procurement records
    UTL_FILE.PUT(v_file_handle,'emp_rec.num');
    END LOOP;
    EXCEPTION WHEN NO_DATA_FOUND THEN
    dbms_output.put_line ('No data found ')
    END;
    EXCEPTION
    WHEN UTL_FILE.INVALID_PATH
    THEN
    DBMS_OUTPUT.PUT_LINE ( 'Invalid Path ' || TO_CHAR (SQLCODE) );
    UTL_FILE.FCLOSE_ALL;
    END;

    cursor for loops do not raise no_DatA_found - they simply stop looping when they run out of data. you can set a variable within the loop, and then check it after the loop if you need to know if data was returned or not.

  • For loop is not working

    Hi,
    I am using a if condition that will first check if the above command ran successfully if the errorlevel is 0 then execute the condition inside the if condition. My syntax is as follows
    if %errorlevel%==0 ( for /f "delims=" %%x in ('dir /b/od C:\Folder ') do set recent=%%x
    set FILE=%recent%
    echo %FILE%
    echo "hello world"
    ) else ( exit 1 
    the for loop is finding the latest file inside the C:\Folder .
    The for loop is working fine , if I remove the if condition, but failing when it is inside the if condition. 
    Kindly help.
    Thanks,
    Ashis

    ":eof" is an inbuilt label that is assumed to be at the end of the code. "Goto :eof" causes the program to jump to that label. Now consider this construct. It demonstrates that "goto :eof" terminates the current segment but not necessarily the batch file.
    @echo off
    call :Sub1
    call :Sub2
    goto :eof
    :Sub1
    if  %value% GTR 5 goto :eof
    echo The value is %value%
    goto :eof
    :Sub2
    echo The date is %date%
    if /i %UserName% EQU Ashissau goto :eof
    echo You are not authorised to use this PC.
    goto :eof

  • Sayit App for Playbook doesn't work

    I cannot get Sayit for the BB Playbook to work. The program states to allow permissions for mic but I don't have any settings to do so After numerous reinstalls (3 different playbooks) still doesn't work. The company doesn't respond to my emails so It leaves me with the impression they are a bogus outfit. Anyone else stuck with apps from BB App world for Playbook that don't work ? Be nice if someone could set up a thread that says which ones work and which don't. This would save time and money for people who pay for an app and then don;t get support ,.At $5.00 per app and maybe thousands of user who download it !!!

    Apple doesn't vet or test apps. those apps meet certain requirements and they're in the app store. Look through there, you'll see plenty of 0 or 1 star apps.
    There are millions of apps and Apple doesn't vet them.
    the facebook app hasn't worked right in years, Apple doesn't care, it's up to Facebook to make their app work. Same applies to Charter
    they will not make a developer make their app work well, they let 'survival of the fittest' rule...good apps get good ratings, bad apps get poor ratings, well rated apps rise to the top, poorly rated apps fall to the bottom.

  • TS3999 Argentina holiday link for iCal doesn't work, please help!!

    İ want to add argentina holiday calendar to my iCal but the link on apple page doesnt work.

    As you say the link doesn't work; neither does its originating domain alone. The note on the page concerned says that the calendar is valid only for 2010 and 2011, so evidently it's been withdrawn and not updated by its originator. I'm afraid that a number of the links on Apple's page have gone dead.

Maybe you are looking for

  • Free Imports Purchase

    Hi, I want to procure some free samples through Import, But for which CVD is applicable. When i give indication for Free items in item overview, then the Conditions tab at item details gets removed. How to achieve this functionality. Whether defining

  • I bought a "just wireless portable battery pack". How do I know it won't fry my Iphone 4?

    I Recently bought a  just wireless brand rechargeable battery pack. How do I know whether or not it will fry my Iphone 4?

  • Flashbuilder 4 and ZEND AMF

    Hello, i have the following setup: This is my ValueObject: <?php class PurchasedSongVO      public $txn_id;      public $article_id;      public $song_id;      public $songName;      public $artistName1;      public $songIcon;      public $songPrevie

  • Iwork 09 help

    I had to reinstall my osx (Leopard, updated to 10.5.8), uninstalled all iwork 09 files, then reinstalled the software from the DVD and all updates. It still won't work. This is the error log sent to apple Process:         Pages [228] Path:           

  • MacBook Pro Retina Movie issues

    Hi guys I am new to the MAC World I  bought my first MacBook Pro Retina 15,4" a week ago The problem that I am having is that I cant make my Sansung Smart TV to see my share movies in the mac :/ I used to have a windows laptop and all I had to do was