How to use a timer

can anyone tell me how to implement a timer in my program
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Sudoku extends JApplet implements ActionListener{
JButton button [][] = new JButton [9][9] ;
public void init()
Container container = getContentPane() ;
container.setLayout(new GridLayout(9,9));
for ( int count = 0 ; count <=8 ; count++)
for (int count1 = 0 ; count1 <=8 ; count1++ )
button [count][count1] = new JButton() ;
button [count][count1].addActionListener (this) ;
container.add(button [count][count1]);
public void actionPerformed ( ActionEvent event )
String output = "" ;
output =JOptionPane.showInputDialog ( "Enter a number between 1-9" );
if ( output.indexOf ('.') != -1 )
JOptionPane.showMessageDialog (null, "Please enter an integer between 1-9 " ) ;
else
int num = Integer.parseInt ( output ) ;
if ( num > 9 || num <1 )
JOptionPane.showMessageDialog ( null, "Re-enter an integer between 1-9" );
else
((JButton)event.getSource()).setText(output) ;
}

It can be done with Treads, in the example below 3 buttons Start , Pause\Resume and Stop manipulate the timer.
     public void actionPerformed(ActionEvent e){
          if(e.getSource() == buttonStart) {
               counterLabel.setText("0 : 0");
               thread = new Thread(this);
               thread.start();
               buttonStart.setEnabled(false);
          if(e.getSource() == buttonStop) {
               thread.stop();
               buttonStart.setEnabled(true);
          if(e.getSource() == pauseButton) {
               if(!isPaused) {
                    thread.suspend();
                    pauseButton.setLabel("Resume");
                    isPaused = true;
               else {
                    thread.resume();
                    pauseButton.setLabel("Pause");
                    isPaused = false;
     public void run(){
          int secondCounter = 0;
          int minuteCounter = 0;
          while(true) {
               try {
                    thread.sleep(1000);
               catch(InterruptedException e) {}
               secondCounter++;
               if (secondCounter == 60) {
                    minuteCounter++;
                    secondCounter = 0;
               counterLabel.setText(String.valueOf(minuteCounter) + " : " +
                    String.valueOf(secondCounter));
}Hope i've been of some assistance!

Similar Messages

  • How to use airport time capsule on a dell portable pc with windows 7 taking in consideration that Time machine doesn't run with Windows ?

    how to use airport time capsule on a dell portable pc with windows 7 taking in consideration that time machine doesn't run with Windows ?

    TM does not work like that.
    If you want files to use later.. do not use TM.
    Or do not use TM to the same location. Plug a USB drive into the computer and use that as the target for the permanent backup.
    Read some details of how TM works so you understand what it will do.
    http://pondini.org/TM/Works.html
    Use a clone or different software for a permanent backup.
    http://pondini.org/TM/Clones.html
    How to use TC
    http://pondini.org/TM/Time_Capsule.html
    This is helpful.. particularly Q3.
    Why you don't want to use TM.
    Q20 here. http://pondini.org/TM/FAQ.html

  • How to use Real time execution trace toolkit with Dual-core processor??

    hi there
    the situation as follows:
    i have a computer (PC and Laptop) types with Dual-core processors, and am trying to do simulation using Multi-core technology and based on different simulation scenarios...starting from sequantial processing,.......Piple lining processing strategy. so that i can differentiate the time delay between those types of processing based on (Using 1 processor then dual-core processor Computers)
    my question is: As i read through Ni's white papers i saw many notes refer to Real-time execution trace toolkit to investigate the (processing-time , etc) of multi-core processors in processing diffenent algorithms. My algorithms are to be run on 1 computer with dual-core processor BUT, not in real time environments, that is ( No hardware to be connected to my pc) only algorithms running on my pc....
    So, is it possible to use Real time execution trace toolkit  or anyother tools in LabVIEW to show processing-delays and/or anyother timing critical issues without using my application for  real- time hardware.???
    in other words: how to use Real time execution trace toolkit  in non-hardware and/or real-time scenarios???
    please help me in this.
    Any suggestion, comments, feedback.....is absolutely highly appreciated
    thanks a lot in advance
    Labview Lover

    Hey,
    The Realtime Execution Trace Toolkit only works for NI RT Targets.
    But you can use the Desktop Execution Trace Toolkit, just search for it under ni.com.
    Christian

  • How to use a timer in director to count down to quit

    how to use a timer in director to count down to quit

    Hello Christos,
    I'm sorry, but I have to give you again some links, at the moment I don't have "selfmade" files for you.
    First these Adobe help files:
    http://help.adobe.com/en_US/Director/11.5/Beginners/WS287f927bd30d4b1f5218ba7912ff9103109- 7feb.html
    http://help.adobe.com/en_US/Director/11.5/UsingScripting/WSc3ff6d0ea77859461172e0811d64c1a 1b3-7ae3.html
    Second an interesting thread from the forum with a "cookbook":
    https://forums.adobe.com/thread/1261561
    Hans-Günter

  • How i USe face time?

    How i USe face time? But i dont have friends to try...how i fond friends for face time

    To use FaceTime you must have a Wi-Fi connection to the Internet.  3G won't do it at this time.
    Also, FaceTime may not be available in all countries or regions.
    See page 65 of the iPhone iOS4 User Guide

  • How to use ftace time

    how to use face time on i phone 4

    iOS: Using FaceTime
    iPhone User Guide (For iOS 4.2 and 4.3 Software)

  • How to use the time machine?

    how to use the time machine? because i don't know where to find the back up. can you please help me.. thankyou.

    Time machine is a backup application and service that come with Leopard. When you plug in an external drive you can use it as a backup source. All you do is select the drive in the Time Machine control panel and start the backup. It will back up your whole drive and if you lose a file, go to the location on your drive where that file should be and open the Time Machine application. From there you will be able to migrate to all the points in "time" when the file was changed, and select the version of the file that you want. Then select "restore" and the file will be restored to the location where it last was on your drive.
    For more information check out the Time Machine website:http://www.apple.com/macosx/features/timemachine.html

  • How to use airport time capsule with multiple computers?

    I'm sure there are some thread about this but i couldn't find it... so sorry for that but hear me out! =)
    I bought the AirPort Time Capsule to back up my MBP
    And so i did.
    then i thought "let give this one a fresh start" so i erased all of it with the disk utility and re-installed the MBP from the recovery disk.
    I dont want all of the stuff i backed up just a few files and some pictures so i brought that back.. so far so good.
    Now i want to do a new back up of my MBP so i open time machine settings, pick the drive on the time capsule and then "Choose" i wait for the beck up to begin, and then it fails.  It says (sorry for my bad english, im swedish haha) "the mount /Volume/Data-1/StiflersMBP.sparsebundle is already in use for back up.
    this is what i want:
    i want the "StiflersMBP.sparsebundle" to just be so i can get some stuf when i need them. it's never to be erased.
    i want to make a new back up of my MBP as if it's a second computer...
    so guys and girls, what is the easiest and best solution?
    Best regards!

    TM does not work like that.
    If you want files to use later.. do not use TM.
    Or do not use TM to the same location. Plug a USB drive into the computer and use that as the target for the permanent backup.
    Read some details of how TM works so you understand what it will do.
    http://pondini.org/TM/Works.html
    Use a clone or different software for a permanent backup.
    http://pondini.org/TM/Clones.html
    How to use TC
    http://pondini.org/TM/Time_Capsule.html
    This is helpful.. particularly Q3.
    Why you don't want to use TM.
    Q20 here. http://pondini.org/TM/FAQ.html

  • How to use my time capsule on my new macbook pro retina (time machine error)

    Hello all,
    I've been using my old mac for a while with my time capsule, but recently I bought the new macbook pro retina and I wanted to use the time capsule as the backup disk on the new one. However, whenever I try to run the backup, a message appears "The backup disk image “/Volumes/Data/XXX’s MacBook.sparsebundle” is already in use."
    I wanted to override the settings so that the new macbook will use the time capsule for its backup disk instead of the old one, as I will no longer be using it.
    I was wondering if anyone had this problem before and if anyone know how I can solve it?
    Thank you

    You could delete the old backup from your old laptop? If you need to keep it then you need to rename that folder so that your new macbook can creatie its own file in the same name.
    Regards,
    Ryan

  • How to use my Time Capsule with my Router?

    My Time Warner Cable HS connection uses a specific modem, the Motorola Surfband SBG6580.
    I was currently using my Tiem Capsule as my router and just a Cable Modem from Time warner, but this particular service uses this wireless router. I need to get my Apple Time Capsule back into my netowrk.
    I would either like to understand how to use the Motorola as a switch or just as a modem so I can use the Time Capsule as my router or vica versa, use my Time Capsule as just a back up drive and leave the Motorola as my rwireless router. The onyly thing about this second configuration is that I need to connect to the Time Capsule wirelessly with one of my computers for back up, the other two are both on an ethernet port hard wired.
    So this is what I have to put in place:
    Motorola Wireless Cable Modem
    Time Capsule
    5 Port EasyNet Switch
    iMac Desktop (Ethernet hardwired)
    Macbook (Ethernet hardwired)
    MacBook (wirelessly connected to the network)
    Any thoughts great appreciated.
    Henry

    It's likely that your ISP will require that the Cable Modem is the first device in the chain. You do need to set the Time Capsule to Bridge mode, disabling the DHCP. Now, the Cable Modem is providing DHCP to devices that connect to it, and devices that connect to the Time Capsule.
    You will be able to wirelessly connect to the Time Capsule and network.
    Here is a simple article explaining:
    http://www.ehow.com/how5309467bridge-time-capsule-mac-pc.html

  • How to use 2 Time trigger UI elements

    Hi Experts,
      My user doesn't want to see the time out error in the webdynpro application after leaving(idle mode) the browser for hours. And one more thing is he wants a popup for every 15mnts to show a message on the screen.
    So, I have used 2 Time Trigger UI elements to achieve this functionality,
          1st one(Time Trigger UI Element) is used to show the pop up message and It is working fine to show the message in a Pop Up .
          2nd one is used to handle the Time Out Error for hours and this is not working as expected, if user leaves the browser for hours .
    I hope you understand my requirement and issue.
    Could you please suggest me how to achieve this functionality.
    1000 Thanks in advance.
    Regards,
    Giri

    Hi,
    If I set the 3 hours to 2nd Time Trigger UI element and tested after 2 hours and browser is still throwing the time out error message.
    After 2hrs is the time out error throwing by the Timed trigger or the standard session time out? I believe after 2 hrs the standard session time out is throwing! You need to give the delay time less than your session time out.
    You can get the session timeout using wdr_task=>server->session_timeout ( in mins ) And you can get the application server time out using
    data: name type pfeparname,
            value type pfepvalue.
      name = 'rdisp/plugin_auto_logout'.   " parameter
      call 'C_SAPGPARAM' id 'NAME'  field name
                                        id 'VALUE' field value.   " value contains time out 
    Regards,
    Kiran

  • How to use real-time tracking and filing in EchoSign

    Click the link to learn how to use the notification, tracking, and filing features available in the Adobe electronic signatures service, EchoSign.

    Hi,
    You can observe the data for executables with the RTSM. Just be sure to
    first go to the Tolls>>RT Taget [x.x.x.x] Options and configure
    the VI Server to use TCP. Then add your desktop machine to the Access
    List on the TCP/IP Access tab. Now VI server should be able to export
    the info. about the executable.
    Richard
    Applications Engineer
    http://www.ni.com
    Richard
    Field Sales Engineer, New Jersey
    National Instruments

  • HT3775 how do use quick time i click on icon and nothing

    I am trying to use quick time and when click I incon it will not open

    jokaro wrote:
    I am trying to use quick time and when click I incon it will not open
    Try posting and doing a search through the Quicktime forums.
    https://discussions.apple.com/community/mac_os/quicktime?view=discussions
    Good Luck
    Pete

  • How to use a timer together with an event.

    Dear All,
    Today I tried all day to accomplish someting with labview, but I didn't succeed. Perhaps you can help me.
    The problem is as follows. 
    I have an event structure inside a while loop. The events are all triggered by booleans. Those booleans initiate
    for instance some pumps or  other apparatus. The time-out is put at 200ms and inside the time-out structure 
    are some GET function (for instance to obtain the values of some balances and to do some calculations with those obtained values.
    Now I would like to be able to start an experiment. This means by pressing a boolean initiate the experiment. This experiment involves 
    the starting of a timer and after every 10 minutes, the obtained/calculated data (from the time-out) structure should be written to a .xls file.
    I'm not able to programm this part of the program. My first problem is that I need an event (triggered by a boolean) that start a timer. This timer should run always (independant of other events) until stopped by another boolean. After every 10 minutes this timer should initiate (with a boolean?) the data writing to a .xls file.  Can this be done by resetting the timer after every writing event?
    So I have multiple questions, but my main question is how to build an event which is trigger by a boolean and then initiates an overall timer.
    Thanks! 
    Bio

    OK.  That worked.
    You have made all the mistakes self-taught beginners with LabVIEW make, except that you apparently have a pretty good idea of what you want your program to do.
    1.  LV is a dataflow language.  This means that any node which has all its inputs satisfied can run and once started any node runs to completion before another starts.  In your event case the timeout case will execute 200 ms after the loop starts (assuming the user did not push a button before that).  The Waits in the sequence frames mean it will be at least 555 ms before the timeout case completes.  200 ms later is will run again, if not other event has occurred.  Furthermore, you do not know whether the Waits will run before or after the other code in each od the sequence frames because there is no data dependency between the Waits and that other code.
    2. A matter of style: It is recommended that front panels and block diagrams do not exceed one screen size.
    3. Local variables violate the dataflow paradigm and are almost always unnecessary.  The WIRE is the variable.  Connect things via wires not local or global variables.  You will also need some shift registers.
    4. Sequence structures are almost never required.  One exception: Single frame structures around something like the Wait function which does not have error clusters for dataflow.
    5. Look at the Producer/Consumer Design Patterns which come with LV.  File >> New.. >> VI >>  From Template >> Frameworks >> Design Patterns..  The events version will be useful.  Also learn about state machines.  That architecture is versatile, powerful, adaptable, and much more likely to get you to where you need to be with your program.
    6. The events will all be queued up in the internal event queue.  It just takes a long time for your program to get to them.  I like to keep the code in every event case simple enough that it executes before the user could get to the next button. The queued message handling in the Producer/Consumer takes care of this.
    7.  You probably should have an event for Stop experiment.  It would send a command to the consumer loop to shut down all pumps, close files, and any other "cleaning up" which needs to be done before stopping the program.
    This may seem like a lot, but you have most of the pieces.  Some re-arrangement and re-organization will help a lot.
    Lynn 

  • How to use old Time Capsule als external disk

    I just bought a new 3TB TC. I want to use the old one as an external disk and I also have some files on there I want to use. the new 3TBTC connected nicely, but the old TC on ethernet cable is not recognized by Mac Pro.
    How do i connect the old TC to Mac Pro to use as occasional external disk?
    thanx
    Frank

    Factory reset the old TC.. plug it by ethernet into the network.. straight into the new TC is the obvious place.
    The Mac should then be able to find it.. if not I can suggest how to do it manually in full isolation from the network.
    Airtport Utility can't find Airport Time Capsule on either of my 2009 Macs

Maybe you are looking for

  • HELP!!! Could someone help me with a jar file issue and JRE 1.3 & 1.4

    We had a problem with the last Oracle patch in that it tried to extract from a jar file using the "jar" executable. But the jar executable is not installed on the server where we have JRE 1.4 On one server, Jar.exe is installed where we have JRE 1.3.

  • Creating an epub file from a Framemaker 10 document

    Are there special tools I have to have to turn a Framemaker document into an epub file format? Thank you.

  • GOS attachment find

    Hi, I would like to find the attachment of a GOS(Generic Object Service) but I will not view attachment.  Is there a function module like this? CALL FUNCTION  '.....' Exporting attachmet = true / false If there is attachment, I will give it icon in t

  • Getting the error during RCU installation

    Hi, I am facing the below error during the installation of RCU.I has given the sys user and the pwd which is working fine from DOSPROMPT.the same when i give in the the configuration during the installation of RCU ,i am getting the below error .Can a

  • Creating html sig with embedded gif

    Hi all, I'm trying to create an html sig for mail, with an embedded gif but am having no success. I do the whole save as archive from safari and give the name of existing temp sig created from mail; and it appears in my mail app correctly except for