Displaying a Simple Timer

i want to display a simple MM:SS count-up timer on screen.
im using:
int time = (int)(curr - start);
Date date = new Date();
date.setMinutes(time / 60)
date.setSeconds(time % 60)
gfx.drawString <- simpleDateFormat.(formatdate) // formatted with "mm:ss"i see those methods as deprecated and i know how to set the equivalent
values in Calendar put i dont see a Calendar formatter.
this would be much simpler if i could skip Date altogether and just use a 1.5 formatter
but this needs to be 1.4.2 friendly.
Any suggestions?

You could also use a DecimalFormat with Calendar#get (...)
This code uses bothe ways ;-)import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
public class CountUpTimer implements ActionListener {
   Calendar calendar = Calendar.getInstance ();
   JFrame frame = new JFrame ("Count up timer");
   JLabel labelCalendar = new JLabel ("00:00");
   JLabel labelDate = new JLabel ("00:00");
   JButton button = new JButton ("Start");
   Timer timer = new Timer (1000, this);
   DecimalFormat dec = new DecimalFormat ("00");
   SimpleDateFormat dtf = new SimpleDateFormat ("mm:ss");
   public CountUpTimer () {
   void makeUI () {
      button.addActionListener (new ActionListener () {
         public void actionPerformed (ActionEvent e) {
            if (timer.isRunning ()) {
               timer.stop ();
               button.setText ("Start");
            } else {
               calendar.set (Calendar.MINUTE, 0);
               calendar.set (Calendar.SECOND, 0);
               timer.start ();
               button.setText ("Stop");
      frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
      frame.setSize (200, 150);
      frame.setLayout (new GridLayout (0, 1));
      frame.add (labelCalendar);
      frame.add (labelDate);
      frame.add (button);
      frame.setLocationRelativeTo (null);
      frame.setVisible (true);
   public void actionPerformed (ActionEvent e) {
      calendar.set (Calendar.SECOND,
            calendar.get (Calendar.SECOND) + 1);
      labelCalendar.setText (dec.format (calendar.get (Calendar.MINUTE)) + ":"
            + dec.format (calendar.get (Calendar.SECOND)));
      labelDate.setText (dtf.format (calendar.getTime ()));
   public static void main (String[] args) {
      SwingUtilities.invokeLater (new Runnable () {
         public void run () {
            new CountUpTimer ().makeUI ();
}db

Similar Messages

  • I am recording with Logic Pro X, using my Yamaha XS8 keyboard as a Midi controller. I also have a Thunderbolt Display. Every time I play and release a note on the keyboard, the Thunderbolt Display speaker emits a doink sound. How do I get it to stop?

    I am recording with Logic Pro X, using my Yamaha XS8 keyboard as a Midi controller. I also have a Thunderbolt Display. Every time I play and release a note on the keyboard, the Thunderbolt Display speaker emits a doink sound. What is causing it and how do I get it to stop? My sound is running through the Saffire Pro 40 Interface (Focusrite) into external speakers with powered amps.
    Also, When I record I am hearing little pops in the system. I have checked all of my meters and they are not clipping. What is causing it and how do I get it to stop?
    Ken

    MUYconfundido wrote:
    Pancenter,
    Thanks for the response, but I do not have a midi interface. I am using a midi to usb connector cable, thus bypassing the need for a Midi interface.
    The Mac reads the USB cable as a midi device, but not the keyboard that I am trying to use as a controller. I have tried it with my korg sp 300 and with my Nord Electro 2.
    Thoughts?
    Thanks,
    Tristan
    Tristan...
    This is what you have, correct?
    http://www.alesis.com/usbmidicable
    This from Alesis..
    "The AudioLink Series USB cable receives and outputs MIDI signal thanks to its internal interface. The USB-MIDI Cable connects plug-and-play to your Mac or PC for an all-in-one USB-MIDI solution."
    Notice, -internal interface-. What you have is a simple USB MIDI Interface. Most MIDI interfaces are USB.
    My point is (was), MIDI OUT of the Korg goes to the connector marked MIDI IN on the Alesis, those new to MIDI often get this wrong.
    pancenter-

  • Displaying Date and Time in portal desktop

    Hi
    I have been looking around for any info or guideline to display the <b>date and time</b> in the portal desktop. I could not find anything very helpfull. In visual admin you can swap lastname and firtsname and vice versa. Thou there is nothing about displaying date and time.
    Is it possible to display it and how?
    Thank you for any information
    Namira

    Where u need the time to be displayed.. If it has to be displayed in Masterhead you can programatically display it...
    import the par file for Masterhead, change it and replace it..
    Its a simple JSP page so that u can change it easliy..
    cheers
    gEorgE

  • New, trying for a simple timer

    I'm new to Labview and I'm trying to make what should be a simple timer.
    Specifications:
    (1) A "Start" button starts the timer.
    (2) A "Stop" button stops the timer.
    (3) A knob controls the timer duration.
    (4) Something (right now it's just a sine wave generator) runs while the timer is running.
    (5) A status LED lights while the timer is running.
    (6) The LED and the "something" in #4 turn off when the timer isn't running.
    (7) The timer does not run when the VI starts up.
    (8) The timer may be turned on or off multiple times while the VI runs.
    I can't get #2 and #7 to work.  The Elapsed Time VI keeps running, so putting my Stop button together with the Time Has Elapsed wire on an "Or" operator doesn't work.  Further, upping the knob value (say, from 2 s to 7 s) after the timer runs out will turn everything back on (because the new, later time hasn't arrived yet).  As for #7, I'm not really sure what to do about that.
    Here's a picture of my latest.  Edit: The True condition is nothing more than a False constant wired to the "Busy" LED.
    Message Edited by DJDDA on 09-29-2007 11:24 AM
    Message Edited by DJDDA on 09-29-2007 11:25 AM

    Sorry, I misunderstood.
    Here's one possible solution. Yes, the big loop currently runs at near infinite speed, consuming all CPU. Typically, you want to place a small wait (e.g.50ms) to make the loop time reproducible between machines and limit CPU use.
    You are also generating 100 points, but you are only displaying one. Seems like a waste.
    Why are you using tiny font on the front panel and arbitrary color distinction (everything is red!). Also, the classic controls are a bit ugly and outdated.
    You should also remember that LabVIEW 8.5 is very new and most here don't have it. If you would convert your VI to 8.0 before attaching, many more can inspect it.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ScinPan1MOD.vi ‏57 KB

  • ICO file not displaying at run time?

    Hello Experts,
    I an using fusion 11.1.2.1 32 bit. I have Copied the Icons as well as GIF files in C:\Oracle\Middleware\Oracle_FRHome1\forms\java folder.
    At button property i set Iconic to yes
    and file = addrow
    Icon not display at run time.
    but when i set file = abc.GIF
    image is displaying at run time.
    My doubt is that ICO file not displaying at run time while GIF file are displaying.
    Do i need to change configuration ?
    Please do the needful.
    Thanks
    Yash

    Hi Yash,
    First Try this steps
    To resolve this issue, follow these steps:
    Double-click My Computer, and then click Options on the View menu.
    Verify that the Icon file type appears on the File Types tab. If the Icon file type does not appear in the Registered File Types box, skip to step 10.
    Click Icon in the Registered File Types box, and then click Edit.
    Verify that the following settings exist, and then click OK:
    The Description Of Type box contains Icon.
    If there is a Confirm Open After Download check box, it should be selected.
    If the settings do not appear exactly as listed in step 4, click Remove, click Yes, and then click OK. If the settings do appear as listed in step 4, skip to step 10.
    Click New Type.
    In the Description Of Type box, type Icon.
    In the Associated Extension box, type ICO.
    Click OK, and then click Close.
    Use Registry Editor to view theHKEY_CLASSES_ROOT\.icokey, and then verify that the default string contains the following value:icofileIf the .ico key does not exist, create it, and then insert the value listed above. If any other values exist in the .ico key, delete them.
    Use Registry Editor to view theHKEY_CLASSES_ROOT\icofilekey, and then verify that the default string contains the following value:iconIf the icofile key does not exist, create it, and then insert the value listed above. If any other values exist, delete them.
    Create a new key in the icofile key called DefaultIcon , and type %1 as this key's default value.
    Quit Registry Editor, and then restart your computer.
    Second Try this
    Simple way
    Copy your images to:
    1
    c:\Oracle\Middleware\as_1\forms\java\ 
    Notes:
    - Icon files may not be supported.
    - In case of a Java security issue when using gif images, you will need to create a jar file and sign it with oracles sign-tool (see below, point 6).
    - In case you having trouble with oracle’s sign-tool, do it directly with java’s
    Recommended way
    1. Create a “icons” folder and place all your gifs in there
    i.e. “c:\Oracle\Middleware\as_1\forms\java\<icons>”
    2. From within icons folder make a jar file of all the gif images:
    1
    jar -cvf frmicons.jar *.gif 
    3. Copy this new jar into “c:\Oracle\Middleware\as_1\forms\java\”
    4. Edit/update formsweb.cfg file:
    path = c:\Oracle\Middleware\user_projects\domains\<my_domain>\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_11.1.1\config\formsweb.cfg  …to update/include:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    # Forms applet parameter 
    codebase=/forms/java
    # Forms applet parameter
    imageBase=codebase
    # Forms applet archive setting for other clients (Sun Java Plugin...etc)
    archive=frmall.jar,frmicons.jar
    # Forms applet archive setting for JInitiator
    archive_jini=frmall_jinit.jar,frmicons.jar
    5. Edit/update Registry.dat file:
    path = c:\Oracle\Middleware\user_projects\domains\<my_domain>\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_11.1.1\config\forms\registry\oracle\forms\registry\Registry.dat
    1
    2
    default.icons.iconpath=icons/ 
    default.icons.iconextension=gif
    At this point your icons should work normally, but if you get a security check of Java for gif files then proceed to the next step to fix this. TIP: May need to restart the weblogic/forms server for changes to take effect.
    6. Sign your jar file with oracles sign_webutil.bat sign-tool.
    path = c:\Oracle\Middleware\asinst_1\bin\sign_webutil.bat
    Firstly, you need to edit the sign_webutil.bat as follows:
    1
    2
    3
    SET KEYSTORE_PASSWORD=my_password 
    SET JAR_KEY=webutil2 # will need to change for every run
    SET JAR_KEY_PASSWORD=my_password
    Secondly, set the environment path and finally run the command:
    1
    2
    3
    set path=c:\Oracle\Middleware\as_1\jdk\bin 
    cd c:\Oracle\Middleware\asinst_1\bin\
    sign_webutil c:\Oracle\Middleware\as_1\forms\java\my_icons.jar
    This will create your signed jar file. Once initialized from the web-app it should ask the user to “Trust” the certificate and never prompt again.
    Other issues you may encounter and may need to edit/update the following files/registry entries as well:
    formsweb.cfg
    path = c:\Oracle\Middleware\user_projects\domains\<my_domain>\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_11.1.1\config\formsweb.cfg
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # Forms applet parameter 
    codebase=/forms/java
    # Forms applet parameter
    imageBase=codebase
    # Forms applet archive setting for other clients (Sun Java Plugin, ...etc)
    archive=frmall.jar, my_icons.jar
    ...or
    # Forms applet archive setting for JInitiator
    archive_jini=frmall_jinit.jar, my_icons.jar
    Registry.dat
    path = c:\Oracle\Middleware\user_projects\domains\<my_domain>\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_11.1.1\config\forms\registry\oracle\forms\registry\Registry.dat
    1
    2
    default.icons.iconpath=/forms/java 
    default.icons.iconextension=gif
    Registry entries:
    1
    2
    UI_ICON:<path_to_icons_dir> 
    UI_ICON_EXTENSION: "gif": ".gif" "ico": ".ico"
    Credits and further information can be tracked for icons issue here and for jar file creation here.
    Hope this will help.

  • Please provide an example of how to display the system time in CNiNumEdit.

    I need to display elapsed time in a numeric edit control. The value must be a double. Using MFC, please show me an example that displays the system time in a CNiNumEdit control.

    The trick is to set the FormatString of the num edit control to a format that displays dates/times and to use the COleDateTime class to handle converting the date/time to a double. COleDateTime encapsulates time stored as a DATE, which is a typedef for double. COleDateTime uses the same conversion factor for date/time as what the num edit expects, and since it supports a conversion operator to a DATE, which is really a double, and the num edit Value property is a double, displaying the current time in a num edit can be as simple as this:
    // Assuming you have a member variable called m_numEdit for a CNiNumEdit
    m_numEdit.FormatString = _T("hh:nn:ss");
    m_numEdit.Value = COleDateTime::GetCurrentTime();
    Hope this helps.
    - Elton

  • Phone only displays 24-hour time after 1.1.3 update

    Is anyone else having the problem that their phone only displays 24-hour time when it wakes up but is still locked? I have it set to 12-hour time and that works properly when the phone is unlocked but while locked, it only shows 24-hour time. Anyone have any thoughts?

    reset the iPhone, hold the home button and sleep button till you see the Apple logo, sounds like a simple software glitch

  • How can I display the elapsed time of the course using Advanced Actions in Captivate?

    I have a Captivate course which is approximately 35 minutes in length. On each slide I would like to display to the user, the current elapsed time.
    EXAMPLE:
    25/35 minutes complete
    The 35 would remain static, so I have been working with the elapsed time system variable in CP: elapsed:$$cpInfoElapsedTimeMS$$
    I can't seem to get the variable to properly display the elapsed time in minutes, rather than miliseconds. Attached is a screen shot of my advanced action.
    Can anyone provide guidence regarding how I should structure this differntly?

    I talked about that Timer widget in that blog post and pointed to another one:
    http://blog.lilybiri.com/timer-widget-to-stress-your-learners
    If you are on CP7, you'll have this widget also as an interaction, which means it is compatible with HTML5 output. Amd there is also an hourglass interaction, with similar functionality but... did not blog about that one
    PS: Check Gallery\Widgets to find all widgets. Default path is set to Interactions

  • HT5019 MacPro laptop display and 2 external monitors (three displays). Can I have more than one application displayed at a time?

    I would like to have my MacPro laptop display and 2 external monitors (three displays). Question, how can I have more than one application displayed at a time? IE: I would like email on one monitor, Finder on my laptop, and iTunes on the other. Possible?
    With extended desktop, it appears that I can only have one application presenting at a time. Sort of defeats the purpose of having multiple displays.
    I am using the HDMI and the mini HDMI connectors.

    I would like to have my MacPro laptop display and 2 external monitors (three displays). Question, how can I have more than one application displayed at a time? IE: I would like email on one monitor, Finder on my laptop, and iTunes on the other. Possible?
    With extended desktop, it appears that I can only have one application presenting at a time. Sort of defeats the purpose of having multiple displays.
    I am using the HDMI and the mini HDMI connectors.

  • Slider for Display and Control Time of Video

    Hey Community,
    I run a Video with the IMAQ/ AVI components. Therefor i want to have a timeband as there is one in a normal video player. The Time runs and if I click on the band the video should jump to this moment of the video. Is there a possibility to manage that or do i have to seperate the display of the time and an extra Control to jump to the point of interest?
    In the file there is a little example what i mean. (LabView 2010)
    Thanks Philipp
    Solved!
    Go to Solution.
    Attachments:
    Slider.vi ‏23 KB

    Hi Philipp,
    you could do that by modifying the "Read AVI File Example.vi" (see Screenshot). I also attached the VI saved with "For previous version", I hope that works for you too.
    This example uses the "IMAQ AVI2 Read Frame VI" function where you can specify the desired frame. So you only have a control that can modifies the current frame, which is normally incremented every loop iteration.
    Best regards,
    Christoph
    Attachments:
    screencapture0.png ‏84 KB
    Read AVI File2.zip ‏27 KB

  • How to display the current time in a UIX page

    Hi All,
    another UIX question....
    A requirement of a customer is to display to current data and time in every page.
    It should be done in a <header>. So i'm writing a new (template based) renderer for that element. How can i display the current time and date on it?
    Thanks in advance for any help...
    Regards,
    Robert Willems

    Hi Robert -
    When you say you are writing a template-based Renderer, do you mean that you are creating a custom look and feel and replacing the header Renderer? If so, I'd recommend instead simply creating your own template (not template-based Renderer), and reference your template directly from your uiXML pages where you want to insert the timestamp.
    You'll probably want to write a method data provider which calls System.currentTime(), convert the result to a date, and then use Java's date formatting capabilities (see java.text.format.DateFormat) to produce a user presentable String that you can return from your data provider.
    For more info (and samples) on templates and data binding, see the "Templates and Data Binding" section of the "Includes and Templating in ADF UIX" help topic:
    http://tinyurl.com/5b7bf
    Andy

  • HOW TO display a simple line of text if the user isn't logged in and not display it if they are?!?!?

    there must be a way to display a simple line of text (or a link) if the user isn't logged in (as wholesale customer), and not display it if they are?!?!?
    it's a basic kind of <php echo> var type of function.... there must be an equivalent in this BC system..... anyone?!?!?     PLEASE!
    thank you
    Chris.

    ok, after chattting with LIVE SUPPORT i've discovered {module_isloggedin}
    now i just need to integrate it into my Online Store modules!

  • I'm trying to add the "Simple Timer" add-on and I can't get it to add on

    I can't seem to download the Simple Timer application to my desktop. I'm NOT a PC kinda guy so I need help.

    Hi Tatt22-
    In response to your question I went to install the Simple Timer extension and was also not able to install it successfully. I've filed a bug with the Add-ons team so that this will be addressed: [https://bugzilla.mozilla.org/show_bug.cgi?id=699910]

  • How to display elapsed/current time of a song in Actionscript.

    Hi I have a question on how I can make my code display a total time for a song from a media player I created with Actionscript 3.0, using XML to load the song track.
    This is my current function which I have done and I am unsure on what the problem is that is not allowing the elapsed time to display in a textfield on my stage.
    stage.addEventListener(Event.ENTER_FRAME, timeElapsed);
    function timeElapsed(e:Event):void
                        var minutesCurr:Number = Math.floor((my_channel.position /1000) /60);
                        var secondsCurr = Math.floor((my_channel.position /1000) % 60);
            if (secondsCurr < 10)
                secondsCurr = "0" + secondsCurr;
            var minutesTot:Number = Math.floor((my_sound.length /1000) /60);
            var secondsTot = Math.floor((my_sound.length /1000) % 60);
            if (secondsTot < 10)
                secondsTot = "0" + secondsTot;
            completeText_txt.text = minutesCurr + ":" + secondsCurr + "/" + minutesTot + ":" + secondsTot;
    I tried adding to the stage and I am getting a null object reference.
    Thanks Casey

    The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....
    - is declared but not instantiated
    - doesn't have an instance name (or the instance name is mispelled)
    - does not exist in the frame where that code is trying to talk to it
    - is animated into place but is not assigned instance names in every keyframe for it
    - is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).
    If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

  • How we can display the running time as an output by writting abap report?

    hi to all,
         my name ahmed iam just abap fresher.i know java/j2ee very well.
    i want to display the runing time as an output of abap report.Is it possible if possible how.

    Hi,
    system field  SY-UZEIT
    WRITE : SY-UZEIT.
    Regards,
    V.Balaji
    Reward if Usefull...

Maybe you are looking for

  • In contacts the country field of the address does not appear in the print pre view or or in the printed label. any suggestions  why or who to correct ?

    In contacts on my new i Mac the country field does not show in the label print pre view or the printed label. Any suggestion of why this is happening?

  • Cleaning up Image quality of old VHS tapes

    Is there anything you can do in final cut pro to clean up the image quality of captured footage.. even slightly? I am capturing a bunch of old VHS and Hi8 tapes from the early 90's and the image quality is quite bad. Is there anything I can do to fix

  • Pdf file creation

    I need to convert large pages files, a book, into embedded font pdf files for submitting to a printer. is acrobat distiller needed? is it a part of acrobat? do I need the pro version? thanks so much. I am very new to this.

  • Options for download PS CS6

    Simple question really but for some reason I am confused. Downloaded the PS CS6 extended and the window came up with options. What is it with option that has me stumped?? Well the options were Adobe Photoshop CS6 (64bit) 563MB Adobe Photoshop CS6 486

  • Adding pic w/ transparency changes bg colour

    Hi, I'm working on an InDesign (CS4) document. It's a flyer with text, coloured background boxes made with the Rectangle Tool and a logo with transparency. The problem is that the adding of the logo with transparent parts seems to change the colour o