How to include Time delay in GUI enviroment

hi all,
i want to include time delay while drawing the shapes in the Canvas. I tried with Thread.sleep() and also delaying methods by making them to loop for large number of times.... but it affects the repainting of my Frame window like just previously executed snippet of the code gets repeated again and the delay between the shapes drawn cannot be visually seen..
Can anyone help me????

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DrawingExample extends JPanel implements ActionListener {
    private Timer timer = new Timer(200, this);
    private Rectangle[] rects = new Rectangle[10];
    private int currentUB;
    private boolean desc;
    public DrawingExample() {
        for(int i=0; i<rects.length; ++i)
            rects[i] = new Rectangle(i*15, i*15, 40, 40);
        timer.start();
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        for(int i=0; i<currentUB; ++i)
            g2.draw(rects);
public static void main(String[] args) {
EventQueue.invokeLater(buildApp);
public void actionPerformed(ActionEvent evt) {
currentUB += desc ? -1 : +1;
if (currentUB == -1) {
desc = false;
currentUB = 1;
} else if (currentUB == rects.length+1) {
desc = true;
currentUB = rects.length-1;
repaint();
static Runnable buildApp = new Runnable() {
public void run() {
JComponent comp = new DrawingExample();
comp.setPreferredSize(new Dimension(300,300));
JFrame f = new JFrame();
f.getContentPane().add(comp);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

Similar Messages

  • How to measure time delayed measurement

    Hi All:
    I am using TDS3064 scope to measure time delay betwwen two channels (using IVI driver
    complience package 2.2 for scope IVI driver). I look through drivers, but not able to find
    delayed measurement function. Is there any alternate way to measure time delay betwwen two
    channels. If possible please provide me example. I am new to LV programming.
    Thanks
    DBhagat

    You have to understand something about IVI class drivers. To support portability, those functions that are common to a class are what you see in the driver. Some scopes might have the ability to measure time delay between trigger points on different waveforms but many don't. If there is such a function supported by your scope, then you can make a call to the instrument specific driver or a VISA Write/Read. Of course, you then loose the portability feature of IVI which, imho, is about the only reason to use IVI class drivers. What I would recomend is that you do a capture of both traces and then do an analysis of the raw data in LabVIEW. One way to do this is with Trigger Detection for 1 Channel (Analyze>Waveform Monitoring palette). Wire each channels data to the function and obtain the time for each trigger event. The function will return the time for each event that you can use to calculate the difference.

  • How to set time delay in javascript for indesign cs2?

    while am running the js, am using function date.getMonth, date.getDate()...
    this function produce the error, which return the function as error message,
    if i set alert before running this every time , am not getting the errror
    how to solve this?
    thanks in advance
    subha

    Dear Subhaoviya
    Please use the below coding and get your date and Time functions
    var today = new Date();
    var myDate = today.getDate();
    Thanks & Regards
    T.R.Harihara SudhaN

  • How to include Time Interval in crystal report

    Hi All,
           I have to create a  crystal report in  XI release 2. In the report I have 2 query side prompts "FromDate" and "ToDate" and one report side prompt "Time Interval". I have to show the data for each time interval between the two dates. means suppose if my "Fromdate" is 23 March 2010 and "Todate" is 25 march 2010 and time interval is 1 hour then I have to show data for each 1 hour time gap. means suppose my data in Db starts from 23 march 2010,11:25:25 then I must show data between 11:25:15 to 12:25:15 and so on...upto 25 march 2010.
         I am not able to retrieve the data accordingly. And how to use the timeinterval to retrieve data from db for that particular time interval.Please reply asap.
    Edited by: anushree2187 on May 21, 2010 7:28 AM
    Edited by: anushree2187 on May 21, 2010 7:37 AM

    you can create a group on the date field and then select how to group it by date, you can go up to the second.

  • How to include time in [Today] in workflow email variable

    I want to add the date/time that an item was added to a library in the email body of a workflow email.  I created a variable and set the date value to Current date.  When the email comes though the date is correct, but the time is 12:00:00 a.m.  Why is that, and is there a way to get the time in the date/time stamp?

    Hi,
    This is one drawback in SharePoint. Whenever you write a field of type "Date and Time" in the workflow email, it will always show the time 12:00:00 AM no matter if you have selected "Date Only" option also. This not only happens in SharePoint Designer's "Send an Email" activity but also happens in Visual studio workflow. There is no inbuilt solution for this and if you are using SharePoint Designer then you cannot get rid of this.
    I was using Visual studio workflows and in order to remove this "12:00:00" part from date, i followed some logic. First i converted my date to a string variable and then used "Trim()" function to trim the "12:00:00 AM" part. Like this i made this working.
    Regards
    Ginni

  • Just got motorola s9, is time delay normal for bluetooth headsets?

    As title says I just got a s9 headset and am very surprised by how good they sound with music ( haven't tried a call yet, I understand call quality *** ). Anyway I'm really noticing how bad the time delay is with these, they are completely useless for watching video and also playing tap tap revenge as the sound is a good second behind whats happening onscreen. Is this just the s9 or is this delay normal with bluetooth headsets?

    There is a slight time delay with any Bluetooth headset that I have ever used for music, and yes it is useless for watching movies or playing games.
    To play devils advocate I think if you are able to watching a movie or playing games, then you should also having no problem using wired headphones.

  • How can I put a time delay between specific events in a while loop?

    How can I put a time delay between specific events within the same while loop? I'm already using the "wait" command to control the overall loop iteration speed. But I want to time the individual events as well.

    Hi Jesse,
    You can use a flat sequence. In each box you can put your individual events and attached wait.
    Don't forget to reduce your total loop time of the time you added in the individual sequences.
    Doc-Doc
    Doc-Doc
    http://www.machinevision.ch
    http://visionindustrielle.ch
    Please take time to rate this answer

  • How to include print date with time on SkillBuilders Schedule Plug In?

    Hi,
    Do you have an idea how to include and get the print date with time on the SkillBuilders Plug In? It shows me the date only, time not included. Have tried to put "HH24:MI", "HH24MI" or Tochar(HH24:MI)? No result??
    select p.fullname, sbip_schedule.start_date(e.event_schedule) start_date
    , sbip_schedule.end_date(e.event_schedule) end_date
    , sbip_schedule.duration_seconds(e.event_schedule) duration_seconds
    , sbip_schedule.calendar_summary(e.event_schedule) calendar_summary
    from app_events e
    Thanks!

    I forget to clarify I am looking for the answer is how to get the print of date with time, Start date with time and End Date with time.

  • I've tried every online tutorial for timer.delay + experimented... how to make it work in this sitch

    Hey,
    I've read literally every single timer.delay tutorial I could find online, on youtube, the official documentation, tons of posts on this forum, etc. What I am trying to say is I looked everywhere before posting for help.
    I have a timer running. It runs throughout the game. I need to modify the speed of that timer when a player either hits a certain second(won't work, because the timer is already running) or when someone gets a certain score(can't get it to work, because timer is running).... so my question is how do I get timer.delay to work when the timer is running throughout the entire game. I tried to control the delay by when someone gets a point, but that didn't work either. I am using a trace statement so I see the seconds and the timer speed. the code looks something like
    randomvariable = new Timer(2000,8);
    timer.addEventListener(MouseEvent.CLICK, loop);
    timer.start();
    function loop
    // my looping code here
    What I posted is psuedo code.
    Any ideas on how to make the timer go faster without delay, since I can't get delay to work under the circumstances I explained? Or is there a work around that I don't know about? I will try to give back to the forums by answering other questions. Oh, I am running this on the timeline, not in a .as file. Thanks so much for your help!

    That's what I thought. I thought if I set a delay inside the function or in an if statement for the var that  prints out  the timer decrease that it would work. It doesn't. I'm using Adobe AIR for IOS, but I doubt that makes a difference in this case. I write timer.delay=500; that should make the timer go at 500 milliseconds. My trace shows the amount of milliseconds didn't change throughout the application. It is quite bothersome, since everything else works and every guide and the docs say what I am doing should work. Any ideas?
    Thanks.
    Sincerely,
    Ryan Satterfield

  • How to add a time delay of microsecond in labview 2011

    can you please help me, how to add a time delay of microseconds in labview 2011 version . I expect a helpful replies

    A delay between what and what?
    Is this plain LabVIEW, LabVIEW RT, or LabVIEW FPGA? What kind of data acquisition hardware are you using?
    What is your OS? An accurate "software only" delay of microsseconds is not possible on windows or any other general purpose OS.
    perumpadapu wrote:
    ... I expect a helpful replies
    To get a helpful reply, you need to provide much more detail on what you are trying to do!
    LabVIEW Champion . Do more with less code and in less time .

  • How to include the 1st data point date time in x

    Hi,
    I use a formular in the Interval from "Axis range and interval"
    =IIF(COUNT(Fields!Date_Reading.value, "DataSet1") <=48 ,1 , 12)
    However, it always missed the 1st data point date/time, please advise on how to include it always ... !
    Thanks !

    Hi kkcci8888,
    Per my understanding that when you using the expression in the Interval you can't see the first date display in the label, right?
    I have tested on my local environment and can reproduce the issue, the issue caused by the setting of the Interval. I assumed the 1st data point date time which haven't display means the minimum date in the report.
    If you have specify an kind of "Interval Type", the first date not display as the label, if you keep the "Interval Type" as "Default", you will get it display correctly.
    I recommend you to do the setting as below to get it display correctly:
    Go to Horizontal Axis Properties
    In Axis Options, Select the Axis Type as Scalar.
    Deselect "Always include zero".
    In Minimum box type [First(Sale_Date)]
    note: make sure you have use the order by Sale_Date in the query to order the date already.
    keep the "Interval Type" as "Default", the default means "Days", try to modify the expression to specify an new value of the Interval and the type will be "Days" by default.
    Click "Labels" on the left pane to check you  haven't select the "Hide first and last labels along with this axis":
    If you still have any problem, please feel free to ask.
    Regards
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • Updating my iPhone 5 software has shortened the number of rings before the answer phone kicks in, how do I extend the time delay?

    Updating my iPhone 5 software has shortened the number of rings before the answer phone kicks in, how do I extend the time delay?

    If the codes Tanzim mentioned don't work, just call your carrier and ask them to extend your time until voicemail picks up, to 30 seconds. They do this routinely.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • How to calculate elapsed time(including time and date)?

    Hi all,
    I want to realize a function that can calculate the elapsed time which include time and date.Below is my thought:get the current time and date and store it to a .txt file then using the latest time and date subtract the time and date stored in the .txt file.how can realize it using the simplest way?I'm using LV7.1.

    Hi Idragon,
    you can do it like this.
    Mike
    Attachments:
    DateTime.PNG ‏12 KB

  • How to find orders in timer delay.

    Hi,
    How to find the orders which are in timer delay.
    Is it from Find Order/Get Order combination. Appreciate your help.

    Hi Srinivas,
    I have actually pasted the optimized version of FindOrder, here is the full xml. As you know, whichever says optional you can remove the below tags.
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="http://xmlns.oracle.com/communications/ordermanagement">
    <soapenv:Header/>
    <soapenv:Body>
    <ord:FindOrder>
    <!--Optional:-->
    <ord:ViewBy>
    <!--Zero or more repetitions:-->
    <ord:View>?</ord:View>
    <!--Optional:-->
    <ord:RemarkFilter>
    <!--Optional:-->
    <ord:RetrieveRemarks>false</ord:RetrieveRemarks>
    <!--Zero or more repetitions:-->
    <ord:AttachmentFilter>
    <!--Optional:-->
    <ord:FileNameMatch>.*</ord:FileNameMatch>
    <!--Optional:-->
    <ord:MinSize>0</ord:MinSize>
    <!--Optional:-->
    <ord:MaxSize>4</ord:MaxSize>
    <!--Optional:-->
    <ord:Format>inlineBase64Binary</ord:Format>
    </ord:AttachmentFilter>
    </ord:RemarkFilter>
    <!--Optional:-->
    <ord:AmendmentFilter>
    <ord:LevelOfDetail>?</ord:LevelOfDetail>
    </ord:AmendmentFilter>
    <!--Optional:-->
    <ord:LifecycleEventFilter>
    <!--Optional:-->
    <ord:RetrieveLifecycleEvents>false</ord:RetrieveLifecycleEvents>
    </ord:LifecycleEventFilter>
    </ord:ViewBy>
    <!--Optional:-->
    *<ord:SelectBy>*
    *<!--Optional:-->*
    *<ord:OrderId>?</ord:OrderId>*
    *<!--Optional:-->*
    *<ord:OrderState>?</ord:OrderState>*
    *<!--Optional:-->*
    *<ord:TargetOrderState>?</ord:TargetOrderState>*
    *<!--Optional:-->*
    *<ord:Reference>?</ord:Reference>*
    *<!--Optional:-->*
    *<ord:Cartridge>*
    *<ord:Name>?</ord:Name>*
    *<!--Optional:-->*
    *<ord:Version>?</ord:Version>*
    *</ord:Cartridge>*
    *<!--Optional:-->*
    *<ord:OrderType>?</ord:OrderType>*
    *<!--Optional:-->*
    *<ord:OrderSource>?</ord:OrderSource>*
    *<!--Optional:-->*
    *<ord:CreatedDate>*
    *<!--Optional:-->*
    *<ord:FromDate>?</ord:FromDate>*
    *<!--Optional:-->*
    *<ord:ToDate>?</ord:ToDate>*
    *</ord:CreatedDate>*
    *<!--Optional:-->*
    *<ord:CompletedDate>*
    *<!--Optional:-->*
    *<ord:FromDate>?</ord:FromDate>*
    *<!--Optional:-->*
    *<ord:ToDate>?</ord:ToDate>*
    *</ord:CompletedDate>*
    *<!--Optional:-->*
    *<ord:Priority>?</ord:Priority>*
    *<!--Zero or more repetitions:-->*
    *<ord:Field>*
    *<!--Optional:-->*
    *<ord:Cartridge>*
    *<ord:Name>?</ord:Name>*
    *<!--Optional:-->*
    *<ord:Version>?</ord:Version>*
    *</ord:Cartridge>*
    *<ord:Path>?</ord:Path>*
    *<!--You have a CHOICE of the next 2 items at this level-->*
    *<ord:EqualTo>?</ord:EqualTo>*
    *<ord:From>?</ord:From>*
    *<ord:To>?</ord:To>*
    *</ord:Field>*
    *<!--Optional:-->*
    *<ord:MaxOrders>?</ord:MaxOrders>*
    *</ord:SelectBy>*
    <!--Optional:-->
    <ord:OrderBy>
    <!--1 or more repetitions:-->
    <ord:OrderField>
    <!--Optional:-->
    <ord:SortBy>?</ord:SortBy>
    <ord:Header>?</ord:Header>
    </ord:OrderField>
    </ord:OrderBy>
    </ord:FindOrder>
    </soapenv:Body>
    </soapenv:Envelope>
    Thanks
    Naveen Jabade

  • How do you allow one component at a time in the GUI to be selected?

    I have a tree and a combo box in my GUI. Does any one know of a method or way to allow the selection of one component at a time in the GUI only?
    For example, if i selected a node in the tree (it becomes highlighted), then made a choice from the combo box...I would like the node in the tree to be deselected.
    Thanks!!!

    Yeah add a focuslistener to everything and on focuslost clear the selection

Maybe you are looking for

  • TS1646 How to remove credit card details? "None" option not there

    How to remove credit card details? "None" option not there

  • My Apps folder is not showing up in iTunes.

    I just updated to itunes 10.0.1 and the applications folder in the library is not there anymore. I can still sync the previously download apps to my ipod touch but I can't find the new app I just downloaded in the itunes store. Help please!

  • Out of the box workflow failed on start when started programatically

    I have an approval workflow (out of the box) associated with a list and need to start it for some items programmatically when some conditions are met.  My application runs under an account which is a farm admin. I do have another user dedicated to st

  • HT2506 How can I open uscis.gov/files/form/n-400.pdf with Preview?

    Problem (A) When I try to open some PDFs, such as uscis.gov/files/form/n-400.pdf with OS X Preview, I get the error message: "Please wait... If this message is not eventually replaced by the proper contents of the document, your PDF viewer may not be

  • WM status in delivery

    Hi experts, I have a query regarding WM status of the delivery item, we are creating delivery with reference to project, material is warehouse managed material WM1 and WM2 views are maintained Material has stock in the storage bin which is maintained