How to prevent timer from repeats

hello there i've made a countdown timer
and i want it when it finishes counting till 0 not repeating from the beginning but do some action
i uesd the method
timer.setRepeats(false);but it stops the timer from counting
i'm using javax.swing.timer;
and here is the code:
import java.math.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Timer1 extends JFrame {
   JComboBox combo = new JComboBox();
   JButton start = new JButton("Start");
   JButton stop = new JButton("Stop");
   JButton clear = new JButton("Clear");
   JTextField time = new JTextField("");
   javax.swing.Timer timer;
   SimpleDateFormat timef = new SimpleDateFormat("HH:mm:ss",Locale.getDefault());
   long startT,stopT;
   Date date=new Date();
   public Timer1() {
      super("Timer");
      timef.setTimeZone(TimeZone.getTimeZone("GMT"));
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent ev) {
            dispose();
            System.exit(0);
      setBounds(10,10,400,200);
      getContentPane().setLayout(null);
      start.setBounds(10,30,100,24);
      start.setBackground(Color.green);
      stop.setBounds(10,60,100,24);
      stop.setBackground(Color.red);
      combo.setBounds(10,90,100,25);
      combo.setBackground(Color.blue);
      clear.setBounds(150,60,100,24);
      clear.setBackground(Color.green);
      combo.addItem("1 Hour");
      combo.addItem("2 Hours");
      combo.addItem("3 Hours ");
      combo.addItem("4 Hours");
      combo.addItem("5 Hours");
      combo.addItem("6 Hours");
       combo.addItem("7 Hours");
      combo.setSelectedIndex(0);
      start.addActionListener(new ActionListener() {
         public void actionPerformed( ActionEvent e ) {
            try {
                 startT=(combo.getSelectedIndex()+1)*60*60*1000;  // change if combo box values changed
            catch (Throwable fe) {
               startT=0;
            startT+=System.currentTimeMillis();
            timer.start();
      stop.addActionListener(new ActionListener() {
         public void actionPerformed( ActionEvent e ) {
            timer.stop();
      clear.addActionListener(new ActionListener() {
         public void actionPerformed( ActionEvent e ) {
            time.setText("");
      time.setBounds(150,30,100,24);
      time.setOpaque(true);
      time.setBackground(Color.pink);
      getContentPane().add(stop);
      getContentPane().add(start);
      getContentPane().add(time);
      getContentPane().add(combo);
      getContentPane().add(clear);
      timer = new javax.swing.Timer(1000, new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            stopT = System.currentTimeMillis();
            time.setText(timef.format(new Date(startT-stopT)));
      setVisible(true);
   public static void main (String[] args) {
      UIManager.put("Label.font" ,new Font("Times New Roman",0,23));
      UIManager.put("Button.font",new Font("Arial",1,21));
      new Timer1();
}

simply the user chooses a time from the combobox say
1 hour
and then hits the start button so the timer begins to
countdown.
my problem here is i want when the countdown timer
reaches 0 hour 0 minute 0 second the frame exit (or
any action)not repeating the default time .
got it?Ah, yes, now I understand. So when the user chooses an interval, 1 hour in this case, you calculate the number of seconds that make up that interval. (Doesn't have to be seconds, depends on the granularity of the choices) Then you count down that many seconds like I described before. Each time the timer ticks, decrement the counter, and also convert the number of second left back into hours, minues, seconds and display that.
So the counter becomes the data model that everything's based on, and you format it for display each tick.
startTimer() {
  int interval = // get the interval selected from the combobox
  int seconds = // convert interval to seconds
  start timer with 1 second period
actionPerformed() {
   seconds--;
   if (seconds == 0) {
      stop timer
      do whatever we were waiting for
   else {
       convert seconds to HH:MM:SS format and display in gui
}

Similar Messages

  • How 2 prevent time from changing on leopard and vista?

    if i maintain successive boots into the same OS on my macbook, the time is shown correctly, whereas on booting into another OS changes the time. how to prevent this from happening?
    Neerav

    From what my brother says says about his set-up (he boots into 64 bit Vista periodically), apparently you can't. My understanding is that the two systems do a different version of time at boot, Vista uses a GMT setting in bios, and I think Mac use a local time in EFI. Anyway, the result is several hours difference between the two. I don't use Boot Camp, but I would think if you are on a network with Internet access, you should be able to have the clock reset automatically using System Prefs->Date and Time, and check the box at the top to automatically set the time from the Apple time server.
    Francine
    Francine
    Schwieder

  • How to prevent iCloudDrive from waking computer from sleep?

    My PC wakes up periodically from sleep. After the checking the event logs, the logs show that iCloudDrive.exe process is causing the computer to wake up from sleep. I do not want to disable all system wake timers, but I do not know how to prevent iCloudDrive from waking up the computer. The expiration date keeps changing forward.
    in Command Prompt (admin):
    C:\windows\system32>powercfg -waketimers
    Timer set by [PROCESS] \Device\HarddiskVolume3\Program Files (x86)\Common Files\
    Apple\Internet Services\iCloudDrive.exe expires at 5:26:25 PM on 4/21/2015.
    In Event Viewer:
    Log Name:      System
    Source:        Microsoft-Windows-Power-Troubleshooter
    Date:          4/12/2015 3:21:56 PM
    Event ID:      1
    Task Category: None
    Level:         Information
    Keywords:     
    User:          LOCAL SERVICE
    Computer:      WIN-CBF43TVLMNC
    Description:
    The system has returned from a low power state.
    Sleep Time: 2015-04-12T18:24:08.280458300Z
    Wake Time: 2015-04-12T19:21:44.326107700Z
    Wake Source: Timer - iCloudDrive.exe
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="Microsoft-Windows-Power-Troubleshooter" Guid="{CDC05E28-C449-49C6-B9D2-88CF761644DF}" />
        <EventID>1</EventID>
        <Version>2</Version>
        <Level>4</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x8000000000000000</Keywords>
        <TimeCreated SystemTime="2015-04-12T19:21:56.645016400Z" />
        <EventRecordID>2838</EventRecordID>
        <Correlation ActivityID="{0D44318C-F225-4D0E-AE0B-76736663674D}" />
        <Execution ProcessID="1888" ThreadID="848" />
        <Channel>System</Channel>
        <Computer>WIN-CBF43TVLMNC</Computer>
        <Security UserID="S-1-5-19" />
      </System>
      <EventData>
        <Data Name="SleepTime">2015-04-12T18:24:08.280458300Z</Data>
        <Data Name="WakeTime">2015-04-12T19:21:44.326107700Z</Data>
        <Data Name="SleepDuration">100</Data>
        <Data Name="WakeDuration">826</Data>
        <Data Name="DriverInitDuration">601</Data>
        <Data Name="BiosInitDuration">909</Data>
        <Data Name="HiberWriteDuration">0</Data>
        <Data Name="HiberReadDuration">0</Data>
        <Data Name="HiberPagesWritten">0</Data>
        <Data Name="Attributes">25612</Data>
        <Data Name="TargetState">4</Data>
        <Data Name="EffectiveState">4</Data>
        <Data Name="WakeSourceType">5</Data>
        <Data Name="WakeSourceTextLength">15</Data>
        <Data Name="WakeSourceText">iCloudDrive.exe</Data>
        <Data Name="WakeTimerOwnerLength">96</Data>
        <Data Name="WakeTimerContextLength">0</Data>
        <Data Name="NoMultiStageResumeReason">0</Data>
        <Data Name="WakeTimerOwner">\Device\HarddiskVolume3\Program Files (x86)\Common Files\Apple\Internet Services\iCloudDrive.exe</Data>
        <Data Name="WakeTimerContext">
        </Data>
      </EventData>
    </Event>

    In the Bluetooth System Preferences click the Advanced button, then uncheck the Allow Bluetooth Devices To Wake This Computer checkbox.

  • Gmail makes a lot of drafts when I am writing an email. How to prevent that from happening?

    When I wite email I have all the time drafts copied. How to prevent his from happening?

    writing Email produced in multiples in all mail
    Multi Copies of Drafts To Gmail Server

  • How to prevent apps from syncing in the new version of itunes?

    Hey there.
    I brang my macbook to Applestore cause it had a problem and they downloaded the latest version of itunes. Everything's fine and my music, videos and apps are in the new itunes like before. But now, when I want to sync my iphone, a pop window asks me to give the password of the itunes account I used to download some of my apps or it will delete them and their data. The problem is that one of these accounts is an old friend's one and I actually lost all contact with him. So basically now I can't sync my iphone at all or it will delete all my apps.
    Has anyone any idea how to sort that out? Or at least knows how to prevent apps from syncing in this new version of itunes?
    Thanks for your help

    Onthe top menu
    View > Show Status Bar.
    The grey bar will now appear at the bottom with the info you want

  • How to prevent Oracle from using an index when joining two tables ...

    How to prevent Oracle from using an index when joining two tables to get an inline view which is used in an update statement?
    O.K. I think I have to explain what I mean:
    When joining two tables which have many entries sometimes it es better not to use an index on the column used as join criteria.
    I have two tables: table A and table B.
    Table A has 4.000.000 entries and table B has 700.000 entries.
    I have a join of both tables with a numeric column as join criteria.
    There is an index on this column in table A.
    So I instead of
      where (A.col = B.col)I want to use
      where (A.col+0 = B.col)in order to prevent Oracle from using the index.
    When I use the join in a select statement it works.
    But when I use the join as inline view in an update statement I get the error ORA-01779.
    When I remove the "+0" the update statement works. (The column col is unique in table B).
    Any ideas why this happens?
    Thank you very much in advance for any help.
    Regards Hartmut

    I think you should post an properly formatted explain plan output using DBMS_XPLAN.DISPLAY including the "Predicate Information" section below the plan to provide more details regarding your query resp. update statement. Please use the \[code\] and \[code\] tags to enhance readability of the output provided:
    In SQL*Plus:
    SET LINESIZE 130
    EXPLAIN PLAN FOR <your statement>;
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);Usually if you're using the CBO (cost based optimizer) and have reasonable statistics gathered on the database objects used the optimizer should be able to determine if it is better to use the existing index or not.
    Things look different if you don't have statistics, you have outdated/wrong statistics or deliberately still use the RBO (rule based optimizer). In this case you would have to use other means to prevent the index usage, the most obvious would be the already mentioned NO_INDEX or FULL hint.
    But I strongly recommend to check in first place why the optimizer apparently seems to choose an inappropriate index access path.
    Regards,
    Randolf
    Oracle related stuff:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle:
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • How to prevent users from creating new folders in share folder directory?

    Hello guys
    I'd like to know How to prevent users from creating new folders in share folder directory but still keep their power of creating new folders in their personal 'my folder'?
    I tried changing the 'manage privilage ---- create folder' to deny certain user accounts, but by doing so, it also stops the user from creating new folders in their 'my folder', which is not good..
    I also tried going into these share folders and tried different access types such as 'change/delete', 'read', 'traverse folder' etc, but none of it work ideally. The 'change/delete' access still allows them to create new folders, 'read' access prevents creating new folders but also take away their power of saving reports..
    Any thoughts on how to take away their ability to ONLY create new folders in share folder areas without affecting their other privileges?
    Please advise
    Thank you

    Easy, on the shared folders root folder only give them 'read' or 'traverse folder' but on the the folder inside the shared folders root folder give them 'change/delete'. That means they can change anything inside those folders but not create any folders at the shared folders root level.

  • How to subtract time from dateTime in xquery?

    How to subtract time from dateTime in xquery??
    In ALDSP i tried to use the function xf:add-days but it is showing an error saying invalid function name. I think this namespace is not valid for ALDSP. Is there is any way to add this function in ALDSP???

    xquery functions and operators documentation is here :
    http://www.w3.org/TR/xpath-functions/
    It sounds like you want to ..
    op:subtract-dayTimeDuration-from-dateTime
    this is not an xquery function that you can call, it is an xquery operation defined by the specification
    I believe you can simply use the '-' operator to use that operation.
    <newDateTime>
    { $myDateTime - $myTime }
    </newDateTime>

  • How to prevent B1 from populating the grid with components?

    Hello group,
    We have customized a form that pops up when user enters a parent item (of a template-type BOM) in the quotation grid.  The form displays the component items and lets the user mark which items to "paste" onto the quotation.  However, B1 automatically populates the grid with the component items once focus moves away from the item code column. 
    <b>How to prevent B1 from populating the grid with components <i>while</i> retaining the parent item in the item code column?</b>  I've tried trapping the Validate event, etc. with no success.

    Instead of setting the parent item up as a template type BOM, you could set up the list of parent/child items on a user table and use this user table to display the items in your pop-up screen.  As the parent item would no longer be a template BOM, Business One would no longer automatically popuplate the grid, and you could write your own code to add only the items selected in your pop-up screen into the grid.
    John.

  • How to PREVENT Time Machine from switching disks

    I have two USB drives. I use one for iTunes and the second for Time Machine backups. Problem is, when I plug in the iTunes disk, if the Time Machine disk is not connected then Time Machine switches to this disk and initiates a backup. I have specified in Preferences that the other disk is for TM; also tried 'locking' the preferences screen. But, still TM continues to start backups onto this iTunes disk when I plug it in (assuming, as above, that its regular disk is unavailable).
    How can I prevent TM from doing this; and force it to wait until its own drive is available? Have checked forums and found no answer. Any help appreciated. Thank you.

    BordeauxQuill wrote:
    If it is useful to anyone else, these are Western Digital My Passport Studio 640GB drives.
    Yup, you're the 3rd or 4th to report it with various models of WDs (one fellow had 3 of them!), and a few weeks ago someone had some Iomegas, I think, too.
    This confusion may well also explain some weird stats in Get Info I noticed last week (such as the drive apparently having used more bytes than its capacity, as I recall).
    Quite likely.
    Thank you for your support. I shall come back and mark the thread resolved when I have reformatted the drive.
    Cool. Also double-check the contents of the one you don't erase; you may find some extra stuff there.

  • How to prevent images from loading?

    I am working on creating a web gallery in Dreamweaver CS3.  The thumbnails are in a horizontal strip within a layer above the full sized image layer, in other words the strip is  hiding part of the image, but only when the image is in a vertical orientation. (the strip has no background, so all that is visible are the actual thumbnails) Upon clicking show/hide text , in a toggle configuration, the strip fades, or shows.   On my computer it works perfectly. However, once uploaded, it takes forever to load the images.
    The problem: Although I have the thumbnail images are set to preload,  all of the full size images are loading as well, which takes alot of time. Is there a way to prevent the full sized images from loading, i.e. only when the thumbnail is clicked?
    Frames, in which one frame is thumbnails, and another the is images, is what I normally would use, and have a page for each image. However, for what I have in mind, it will not work (transparency on parts of one frame above another is as far as I can tell not possible).
    So how do I prevent images from loading until called for?  regards~bill-o

    t would help if you posted a link to the page, but I can guess that you have properly diagnosed the cause - the page is encumbered with the weight of all of the full-sized images.
    The only way to not have this happen would be to dynamically write the link to the full sized-images on demand, as it were.  In other words, the link ISN'T EVEN ON THE PAGE until you have clicked on the corresponding thumbnail, and only at that point is the weight of that image experienced.  One easy way to do this is to use the SetText of Container behavior that is part of DW's native arsenal of behaviors.  When the thumb is clicked, the SetText behavior is called to write the image link into the enlarged image's container. Need to see a demo?  Look here -
    http://dreamweaverresources.com/tutorials/settextoflayer.htm
    The behavior is called "Set Text of Container", and using it will meet all of your requirements.
    To use it, you will have to have the following:
    1.  A page with a 'container' which is to receive the enlarged image - this could be a table cell, a paragraph tag, a div, or even a span tag.
    2.  That container will have to be identified with an ID attribute and a valid value, e.g., <div id="enlargedImage">.
    3.  A dummy page containing each enlarged image, placed sequentially on the page.
    To implement the effect, do the following:
    1.  Open the dummy page in Code view, and select the first image's tag, e.g., <img src="images/foo.jpg" width="123" height="256" alt="whatever" /> (XHTML syntax shown here).
    2.  Switch to the actual page, select a thumb that will 'open' this enlarged image, and enter "javascript:;" (that's colon semicolon) in the 'Link' field of the Property inspector to make this thumbnail image a null link.
    3.  Apply the Set Text of Container behavior.
    4.  Paste the clipboard into the dialog for the behavior, and click OK to close the dialog.
    5.  Examine the Behavior panel to see which mouse event has been defaulted - probably 'onclick'.  If you would rather have this be 'onmouseover' use the Behavior panel Event selector (the dark triangle to the right of the event name) to select 'onmouseover'.
    5.  Repeat from #1 above until all thumbs have been treated.
    Let us know if this does not make sense

  • How do prevent firefox from loading(going to) a website(following a link, etc...) that i never want to see again(example: choose now & click on some link in the future)?

    I go to a website(link, etc...) & I never want to go there again, but sometime(anytime) later I come across some page that seems to be useful. I click on a link, and the other required links until I find that it is a waste of time & I then kind of remember having been there in the past & have wasted all this time again. This happening for many different sites over time.
    How do I prevent firefox from loading(going to) all websites that I choose to go to when I have in the(distant) past decided that I never wish to return to: block websites with message saying that I blocked it?

    Hello Cen.
    You need to find an extension that blocks certain sites. I am certain there are many. Search over at [http://addons.mozilla.org addons.mozilla.org].
    I hope you find it.
    If you need help, just ask.

  • How To Prevent ATV From Deleting Previously Synced Files?

    Hi,
    Due to the limited size of my laptop hard drive I have to move the downloaded movies and music video from iTunes to an external USB hard drive after syncing them with the ATV.
    I double click in iTunes the moved file to relocate it again on the external drive so it won't appear as a missing or deleted file.
    But just today, iTunes started to sync a new downloaded movie and erased all of the files that I removed from the laptop hard drive.
    So who can I prevent ATV from deleting those relocated files?
    Thanks.

    if itunes opens up and the external drive is not attached, it is going to flag any file it references on the external drive as unavailable. if the file is not made available and located by itunes before the apple tv syncs with itunes, then the file will also be made unavailable to the apple tv (correct me if i've got this wrong, but i'm fairly certain this is how it goes).
    itunes and apple tv utilize a sync relationship, and in any device/host sync relationship one or the other has to win during a database conflict.
    iTunes always wins if the file originates from itunes (i say this because when you purchase from the ATV, the ATV will push the file to iTunes that first time, but afterward if you remove it from iTunes it will be removed from the Apple TV. This is a little bit off subject but it is relevant as it is the only time the Apple TV gets to win). Otherwise, if it's not in iTunes, it won't be on the apple tv (when the two sync with each other).
    if you want to prevent the ATV from deleting the relocated files, make sure they are available in itunes when the ATV syncs with itunes.
    let us know if you make any observations where the files are available and this continues to happen.

  • How to prevent iPhoto from importing automatically

    There are times I want to load photos onto my computer but do not want iPhoto to import them.
    How can I prevent iPhoto from importing photos automatically when photos are loaded onto my computer?
    Thanks for your help and suggestions.

    Matt,
    That's quite a full trash can. To clarify, we're talking about the iPhoto Trash at the bottom of the Source Pane (left column) and not the regular Finder trash can that lives on your Desktop, right? If there are photos you wish to save in the iPhoto trash, drag them to the word Library at the top of the Source Pane and they will be restored to the library. When you're ready you can try to empty the trash: from the menu bar choose iPhoto > Empty trash. However, you may have trouble with so many files at once. If the trash won't empty you'll have to move the files back to the library and delete them in smaller batches (say 500) until they're all gone.
    Where was the iPhoto library recovered photos folder? Did you see it in the Source Pane of the iPhoto window, or was it inside the iPhoto Library folder in the Finder?
    Regards.

  • How to prevent Premiere from shifting timeline around

    Every time I delete or shorten footage, Premiere Elements 8 automatically shifts my whole timeline over to fill in the gap... and it is really annoying me because I don't want it to do that.
    What really bothers me, is that sometimes it doesn't shift the whole timeline over. Sometimes it will shift one of my audio and video tracks, but not the 3rd or fourth track which causes my whole project to go out of sync just because I shortened/deleted something on the timeline.
    There must be a setting somewhere that prevents Premiere from automatically closing the gaps... but I can't find it...
    Can someone tell me how to change this?

    texdig2
    This is a 3 year old thread in which the participants have not signed into the thread or Adobe Premiere Elements Forum in months/years. It was the time of Premiere Elements 8.0/8.0.1 apparently.
    What do you want to do in Premiere Elements 13 - create a fast motion effect in a video clip in Premiere Elements 13 without the clip to its right moving to the left
    to fill the gap created during creation of the fast motion effect or other?
    In Premiere Elements 13 Expert workspace, I find that I can create a fast motion video effect with Tools/Time Remapping and return to the Expert workspace with the gap maintained.
    Whereas, if I use Time Stretch, the gap is closed automatically. See screenshot for details ...first set of 3 clips, where Time Remapping Fast Motion 4x was applied to the second clip and second set of 3 clips where Time Stretch Speed % = 400 was applied to the second clip. Note audio consequences if audio involved.
    ATR

Maybe you are looking for