Help ! inaccurate time recorded using javax.swing.timer

Hi All,
I am currently trying to write a stopwatch for timing application events such as loggon, save, exit ... for this I have created a simple Swing GUI and I am using the javax.swing.timer and updating a the time on a Jlabel. The trouble that I am having is that the time is out by up to 20 seconds over a 10 mins. Is there any way to get a more accruate time ?? The code that I am using is attached below.
private Timer run = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
timeTaken.setText("<html><font size = 5><b>" + (df.format(timeHours)) + ":" + (df.format(timeMins)) + ":"
+ (df.format(timeSeconds++)) + "</b></font><html>");
receordedTimeValue = ((df.format(timeHours)) + ":" + (df.format(timeMins)) + ":"
+ (df.format(timeSeconds)));
if (timeSeconds == 60) {
timeMins++;
timeSeconds = 0;
if (timeMins == 60) {
timeHours++;
timeMins = 0;

To get more accurate time you should use the System.currentTimeMillis() method.
Try this code :
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CountUpLabel extends JLabel{
     javax.swing.Timer timer;
     long startTime, count;
     public CountUpLabel() {
          super(" ", SwingConstants.CENTER);
          timer = new javax.swing.Timer(500, new ActionListener() { // less than or equal to 1000 (1000, 500, 250,200,100) 
               public void actionPerformed(ActionEvent event) {
                    if (startTime == -1) {          
                         count = 0;               
                         startTime = System.currentTimeMillis();
                    else {
                         count = System.currentTimeMillis()-startTime;
                    setText(getStringTime(count));
     private static final String getStringTime(long millis) {
          int seconds = (int)(millis/1000);
          int minutes = (int)(seconds/60);
          int hours = (int)(minutes/60);
          minutes -= hours*60;
          seconds -= (hours*3600)+(minutes*60);
          return(((hours<10)?"0"+hours:""+hours)+":"+((minutes<10)?"0"+minutes:""+minutes)+":"+((seconds<10)?"0"+seconds:""+seconds));
     public void start() {
          startTime = -1;
          timer.setInitialDelay(0);
          timer.start();
     public long stop() {
          timer.stop();
          return(count);
     public static void main(String[] args) {
          JFrame frame = new JFrame("Countdown");
          CountUpLabel countUp = new CountUpLabel();
          frame.getContentPane().add(countUp, BorderLayout.CENTER);
          frame.setBounds(200,200,200,100);
          frame.setVisible(true);
          countUp.start();
Denis

Similar Messages

  • Don't know how to use the swing timer

    Hi there,
    I did this stupid game for training purposes: There are 3 buttons, 2 of them are "correct", 1 exits the program and you lost.
    It works so far but when clicking the "wrong" button I thought of changing the frame to red, let the program wait for another second and only then closing the window. But somehow that doesn't work. I understand that I have to use the timer class, but somehow I don't really know how.
    Thanks for helping.
    Modify the program of Exercise 3 so that only one button exits the program. If the user clicks on any of the other two
    buttons, the frame just changes color. The user keeps clicking until the "loosing button" is clicked. The user's goal
    is to click as many times as possible.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Random;
    public class Kap59A4 extends JFrame implements ActionListener
      JButton button1 ;
      JButton button2 ;
      JButton button3 ;
      JLabel noGames ;
      int gameCounter = 0;
      // constructor
      public Kap59A4(String title)                          
        super( title );
        button1 = new JButton("Button 1");
        button2 = new JButton("Button 2");
        button3 = new JButton("Button 3");
        noGames = new JLabel("Game#:  ");
        // register the Kap59A4 frame as the listener for the button.
        button1.addActionListener( this );
        button2.addActionListener( this );
        button3.addActionListener( this );
        setLayout( new FlowLayout() );
        add( button1 );
        add( button2 );
        add( button3 );
        add( noGames );
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );  
      public void actionPerformed( ActionEvent evt)
        Random rand = new Random();
        int number = Math.abs( rand.nextInt() )%3; // number gets a number from 0 to 2
        if (number != 0)
          gameCounter++;
          noGames.setText("Game#: "+ gameCounter);
          getContentPane().setBackground( Color.green );
          repaint();
        else
          getContentPane().setBackground( Color.red );
          new Timer(1000, this).start();
          System.exit(0);
      public static void main ( String[] args )
        Kap59A4 demo  = new Kap59A4( "Click a Button" ) ;
        demo.setSize( 300, 100 );    
        demo.setVisible( true );     
    }

    Rather than pass the Timer constructor this, which would be the JFrame itself, thus resulting in the action handler for the buttons being invoked again, you should probably pass it a whole different ActionListener instance that performs the precise action you want to happen a second later.
    And actually, you should probably do that for all the buttons as well -- give each an inner class implementing ActionListener so you can control the behavior of each button, and don't make the JFrame subclass implement ActionListener. Furthermore, I'd advise against subclassing JFrame.

  • Javax.swing.Timer not working or event not being captured by actionPerfrmd

    Here is the code:
    public class nQueensEst extends JApplet implements ActionListener {
      public Timer t = new Timer(1, this);
    //...the actionPerformed:
    if(e.getSource() == jButton1){
                nRainhas=Integer.parseInt(javax.swing.JOptionPane.showInputDialog("Quantas rainhas voc? deseja?"));     
                t.start();
                int contadorTentativas=1;
                for(int i=0; i<=100; i++){
                    sol=new int[nRainhas];
                    while(!rainhas()){
                      jLabel1.setText(contadorTentativas +" tentativas!!!");
                      contadorTentativas++;            
                    jLabel2.setText("Solu??es: "+Integer.toString(i));
    t.stop();
    }else if(e.getSource() == t){
         System.out.println("timer");
         rodadas++;
    Any clue?
    Thanks

    Let me explai the context: i had to implement a classic nQueens problem using a Grasp Algorithm and a Backtrack algorithm, then in dorder to compare them, i want to make the garap one to run find 100000 solutions and register the time it is needes, then divide by 100000. so i need the timer running and making a variable increase every millisecond from the beggining until the end of the last solution. But the timer is not generating a event or the event is not being caought by the actionPerformed.

  • Newbie compiler help using javax.swing class

    current java ver java version "1.5.0_02"
    error msg
    [error]
    C:\Documents and Settings\Neil\Desktop\Java>javac neiltest2.java
    neiltest2.java:12: package javax does not exist
    import javax.swing;
    ^
    neiltest2.java:28: cannot resolve symbol
    symbol : variable JOptionPane
    location: class neiltest2
    JOptionPane.showMessageDialog(null, "The total is " + intSum);
    ^
    2 errors
    [error]
    * neiltest2.java
    * Created on 02 June 2005, 19:02
    * @author  Neil
    * @version
    import javax.swing;
    public class neiltest2 {
        /** Creates new neiltest2 */
        public neiltest2() {
        * @param args the command line arguments
        public static void main (String args[]) {
            int intSum;
            intSum = 14+35;
            JOptionPane.showMessageDialog(null, "The total is " + intSum);
            System.exit(0);
    }TIA
    Neil

    Use either
    import javax.swing.JOptionPanel;
    or
    import javax.swing.*;
    � {�                                                                                                                                                                               

  • TS1741 my i pad is lock up and i cant get it unlocked can you please help the password was used to many times

    my i pad is lock can someone please help  the password was used to many times

    If you have forgotten the iPad passcode and you cannot unlock the device, you have to restore the device within iTunes. You want to use the same computer that you always sync with so that you can restore your iTunes content. You can restore with any other computer, but you will lose everything on the iPad.
    Instructions can be found here.
    http://support.apple.com/kb/ht1212
    You will probably need to restore using Recovery Mode. You can read about it here.
    http://support.apple.com/kb/ht4097

  • How to create a calculator by using javax swing

    I try to us Javax swing make some buttons like 0 - 9 then input some numbers by using those number like a calculator. But I only can get numbers no more than 9.
    Please help me.

    How do you store the number the user enters? If it's in a string and the previous value was eg "1" and the user enters "2" you get "12" with a simple concatenation: val += input.
    OTOH, if you work with doubles and the previous value was 1.0 and the user enters 2.0 by pressing the button you get 12.0 by multiplying 1.0 with 10 and adding 2.0: val = 10*val + input.

  • Configuration Time Recording subsystem to Person time event

    Hi All,
    I need to configuration for Time Recorded data which is exported in an excel sheet now i need to update it in the system...and possibly made a system by that the end user can do it occationally after som trainnig...
    Thanks in advance...
    Amol

    Hi Amol,
    The Time Events that are recorded from an External System will be downloaded into an Excel and this falt file has to be in the correct format so that the Standard program can upload the values in IT2011.
    Use this standard program to upload the Excel from a the desktop or on the application server.
    RPTEUP10 (Upload time events).Sit with ur ABAP'r who will give u the flat file format.
    Structure of field string EXTREC:
    PERNR(8)  Personnel number
    ZAUSW(8)  ID number (infotype 0050)
    LDATE(8)  Date of clock-in/out
    LTIME(6)  Time of clock-in/out
    ERDAT(8)  Date of entry
    ERTIM(6)  Time of entry
    SATZA(3)  Time event type
    TERID(4)  Terminal ID
    ABWGR(4)  Att./absence reason
    Please let me know if u require any further info.
    Thanks and Regards
    Swati

  • Help needed on clearing concept regarding javax.swing.Timer.

    Hello,
    I am not able to understand the concept of Timer. Say suppose
    1) i extend JFrame and create my own frame object
    2) i extend JPanel and create my own panel object
    3) in frame object's constructor i create a panel's object
    4) in panel object's constructor i create a Timer class's object and perform slideshow
    5) after some time ( say when index reaches to 5 i stop timer using timerObj.kill() )
    6) when this timer stops i want the panel object to be removed from frame. This means i need
    to write some code in frame object's constructor that will wait till the timer is running and when it is stopped i would say remove(panelObject). But how to do this??
    Thanks in advance ! :)

    no i don't want to remove the panel within the statement that cancels the timer because basically i want to lot more things also like performing some other kind of animation etc. How can i remove from withing frame's constructor only?i tried the following things :-
    try{
                Thread.currentThread().join();
    catch(InterruptedException ex){           
    while(panelObj.tmObj.isRunning()){
                try{
                    Thread.currentThread().sleep(1000);
                catch(InterruptedException ex){
            }but none of them seems to work. When i write either of the above code nothing happens. Even the window does not appear :(
    Edited by: Salman4u on Mar 31, 2009 9:07 PM

  • How can I search the time capsule using spotlight or time machine?

    Every time I try to use spotlight in finder, to find anything on the time capsule, spotlight automatically turns to the mac.
    While using timemachine the connection to the time machine greys out.
    How can I use these options, or different options to search the time capsule?

    I've been looking for the star wars gui, but I only ended up watching scifi movies all night.
    LOL..
    Oh well it is new year.. seems as good a use of time as any.
    Click on the time machine icon in the dock.. that opens finder inside the backup.
    http://www.dummies.com/how-to/content/using-time-machine-to-find-old-files-on-yo ur-mac.html

  • Why does the message time / date use the original time sent?

    Hi,
    I notice that emails that are delayed come in using the time originally sent, rather than the time that they reach my server. This is unusual, since it can end up with a "new" message ending up well down the list from other messages sent more recently.
    Is that the intended operation?
    Note the following header - this shows up in my inbox based on the 2:57 creation time, even though it didn't even leave the originating server until substantially later.
    From - Tue Mar 25 21:59:03 2014
    X-Account-Key: account2
    X-UIDL: UID86003-1263191493
    X-Mozilla-Status: 0001
    X-Mozilla-Status2: 00000000
    X-Mozilla-Keys:
    Return-path: <[email protected]>
    Envelope-to: [email address removed]
    Delivery-date: Tue, 25 Mar 2014 15:11:16 -0700
    Received: from og1.ijnet.net ([216.246.89.40]:47913)
    by napkin.mysitehosted.com with esmtp (Exim 4.82)
    (envelope-from <[email protected]>)
    id 1WSZYx-00074s-NB
    for [email address removed]; Tue, 25 Mar 2014 15:11:15 -0700
    X-Envelope-From: [email protected]
    X-Envelope-To: [email address removed]
    Received: From hopkins.tea.state.tx.us (198.214.98.149) by og1.ijnet.net (MAILFOUNDRY) id VQwf2rRqEeOelwAw for [email address removed]; Tue, 25 Mar 2014 22:10:59 -0000 (GMT)
    Received: from ([198.214.97.182])
    by hopkins.tea.state.tx.us with ESMTP id 5503449.345156795;
    Tue, 25 Mar 2014 16:48:03 -0500
    Received: from miller (miller.tea.state.tx.us [198.214.97.182])
    by miller.tea.state.tx.us (AIX5.2/8.11.6p2/8.11.0) with ESMTP id s2PLgCe45034;
    Tue, 25 Mar 2014 16:42:12 -0500
    Received: by LIST.TETN.NET (LISTSERV-TCP/IP release 14.5) with spool id 204073
    for [email address removed]; Tue, 25 Mar 2014 16:32:55 -0500
    Approved-By: [email address removed]
    Received: from hopkins.tea.state.tx.us (hopkins.tea.state.tx.us
    [198.214.98.149]) by miller.tea.state.tx.us (AIX5.2/8.11.6p2/8.11.0)
    with ESMTP id s2PJvne69120 for <[email address removed]>; Tue, 25 Mar 2014
    14:57:49 -0500
    Received: from ([198.214.97.51]) by hopkins.tea.state.tx.us with ESMTP id
    5503449.345151870; Tue, 25 Mar 2014 14:57:47 -0500

    That workaround only applies to an IMAP account where only headers are downloaded. Fairly uncommon really as that is not the default.
    The received date is available in the pane always, just right clicking the headers and selecting it from the list is all that is required. Sorting by the order received however negates all the dates and maintains the strict order of mail received. However all of these things are on the View > sort order menu, including grouped by sort that beloved today yesterday last week sorting of Outlook users.
    Funnily enough, I find everything about Outlook without exchange awkward and somehow limited, but it is an exchange client really not a general mail client in my opinion.

  • How to use javax.swing in Pocket PC

    I want to write an application with Swing GUI interface and run on my Pocket PC (iPAQ H3870). It is possible?
    I am using Jeode VM now.
    Thanks.

    I ran across a product called CrEme, that claims to support swing 1.1.1. I used the evaluation and it seemed to work much like Jeode. I never tried working with swing with it. Here is a link with information about CrEme:
    http://www.nsicom.com/news/pressrelShow.asp?ID=304&CategoryID=1

  • System Time +Calendar using Swing

    Hi
    I'm trying to create Swing Appliation that displays the System time.but i don't know how to display it on the window.I imported package from java.util.calendar.* but i dont know how to use it.
    Also how can i create Calendar with help swing appliation?
    Sorry for my post in this thread but i' wasn't sure where to post it.So posted here.

    maheshkale wrote:
    I'm trying to create Swing Appliation that displays the System time.but i don't know how to display it on the window.I imported package from java.util.calendar.* but i dont know how to use it.--------
    I've written up a little clock widget that extends JLabel, so it should work with any Swing application. Hope it's not too long... Feel free to edit it. The enums are just for looks and can be replace with something else.
    It just works off of a Timer every second to update the time in the label, and can display in various formats.
    import javax.swing.JLabel;
    import java.awt.event.*;
    import java.util.*;
    * Simple clock display for JComponents. Displays in a variety of formats.
    public class Clock extends JLabel implements ActionListener {
         private static final long serialVersionUID = 1L;
          * Day of week.
         public static enum Day {
               * Sunday (0).
              SUNDAY( "Sunday", "Sun" ),
               * Monday (1).
              MONDAY( "Monday", "Mon" ),
               * Tuesday (2).
              TUESDAY( "Tuesday", "Tues" ),
               * Wednesday (3).
              WEDNESDAY( "Wednesday", "Wed" ),
               * Thursday (4).
              THURSDAY( "Thursday", "Thu" ),
               * Friday (5).
              FRIDAY( "Friday", "Fri" ),
               * Saturday (6).
              SATURDAY( "Saturday", "Sat" );
               * Full name of this day.
              public String name;
               * Shortened name of this day.
              public String s;
              Day( String name, String s ) {
                   this.name = name;
                   this.s = s;
          * A month of the year.
         public static enum Month {
               * January (0)
              JANUARY( "January", "Jan" ),
               * February (1).
              FEBRUARY( "February", "Feb" ),
               * March (2).
              MARCH( "March", "Mar" ),
               * April (3).
              APRIL( "April", "Apr" ),
               * May (4).
              MAY( "May", "May" ),
               * June (5).
              JUNE( "June", "Jun" ),
               * July (6).
              JULY( "July", "Jul" ),
               * August (7).
              AUGUST( "August", "Aug" ),
               * September (8).
              SEPTEMBER( "September", "Sep" ),
               * October (9).
              OCTOBER( "October", "Oct" ),
               * November (10).
              NOVEMBER( "November", "Nov" ),
               * December (11).
              DECEMBER( "December", "Dec" );
               * Full name of this month.
              public String name;
               * Shortened name of this month.
              public String s;
              Month( String name, String s ) {
                   this.name = name;
                   this.s = s;
          * This clock should display in words and numbers.
         public static final int ALPHANUMERIC = 1;
          * This clock should display in numbers.
         public static final int NUMERIC = 2;
          * This clock should only display the date.
         public static final int DATEONLY = 0;
          * This clock should display both date and time.
         public static final int DATETIME = 1;
          * This clock should display only the current hh:mm:ss time.
         public static final int TIMEONLY = 2;
          * Convenience value to mean the default choices (Date and Time in words and
          * numbers).
          * @see #ALPHANUMERIC
          * @see #DATETIME
         public static final int DEFAULT = 1;
         protected int display, what;
         protected javax.swing.Timer timer;
          * Create a new Clock with given display details and horizontal alignment.
          * <p>
    Display:<code><ul><li>ALPHA</li><li>ALPHANUMERIC</li><li>NUMERIC</li></ul></c
    ode>
          * </p>
          * <p>
    What:<code><ul><li>DATEONLY</li><li>DATETIME</li><li>TIMEONLY</li></ul></code
    >
          * </p>
          * The value <code>DEFAULT</code> applies for both.
          * <hr />
          * See <code>javax.swing.JLabel( String, int )</code>
          * @param display
          * @param what
          * @param align
         public Clock( int display, int what, int align ) {
              super( "", align );
              setDisplay( display );
              setWhat( what );
              timer = new javax.swing.Timer( 1000, this );
              timer.start();
         public void actionPerformed( ActionEvent evt ) {
              setText( getFormattedTime( display, what ) );
          * Get how this clock displays.
          * @return display
         public int getDisplay() {
              return display;
          * Get what this clock displays.
          * @return what
         public int getWhat() {
              return what;
          * Set how this clock displays.
          * @see #ALPHANUMERIC
          * @see #NUMERIC
          * @see #DEFAULT
          * @param display
          *        New <code>display</code> int.
         public void setDisplay( int display ) {
              this.display = display;
          * Set what this clock displays.
          * @see #DATEONLY
          * @see #DATETIME
          * @see #TIMEONLY
          * @see #DEFAULT
          * @param what
          *        New <code>what</code> int.
         public void setWhat( int what ) {
              this.what = what;
          * Get a formatted string of the current time according to given details.
          * @param display
          *        How to display.
          * @param what
          *        What to display.
          * @return Formatted <code>String</code>.
         public static String getFormattedTime( int display, int what ) {
              String ret = "";
              Calendar cal = Calendar.getInstance();
              switch ( what ) {
                   case DATEONLY:
                        int m = cal.get( Calendar.MONTH );
                        int d = cal.get( Calendar.DAY_OF_MONTH );
                        int w = cal.get( Calendar.DAY_OF_WEEK );
                        int y = cal.get( Calendar.YEAR );
                        switch ( display ) {
                             case ALPHANUMERIC: // dow, Mmm dd, yyyy
                                  Day wk = Day.values()[ w ];
                                  Month mn = Month.values()[ m ];
                                  ret += wk.name + ", " + mn.name + " ";
                                  ret += String.valueOf( d ) + getAfter( d );
                                  ret += ", " + String.valueOf( y );
                                  break;
                             case NUMERIC: // mm/dd/yyyy
                                  ret += String.valueOf( m ) + "/";
                                  ret += String.valueOf( d ) + "/";
                                  ret += String.valueOf( y );
                                  break;
                             default:
                        break;
                   case DATETIME:
                        ret += getFormattedTime( DATEONLY, what );
                        ret += " " + getFormattedTime( TIMEONLY, what );
                        break;
                   case TIMEONLY:
                        int hou = cal.get( Calendar.HOUR );
                        int min = cal.get( Calendar.MINUTE );
                        int sec = cal.get( Calendar.SECOND );
                        switch ( display ) {
                             case ALPHANUMERIC: // time is only numeric
                             case NUMERIC:
                                  ret += asString( hou ) + ":";
                                  ret += asString( min ) + ":";
                                  ret += asString( sec );
                        break;
                   default:
              return ret;
          * Format a number and return a string of length 2, with 0 preceeding any
          * value.
          * @param num
          *        Number to format.
          * @return "00", "0#", "##", etc...
         public static String asString( int num ) {
              String ret = String.valueOf( num );
              for ( int i = ret.length(); i <= 2; i++ ) {
                   ret += "0";
              return ret;
          * Return the "st", "rd", etc... after <code>day</code>.
          * @param day
          *        Day of month, 1-31
          * @return String
         public static String getAfter( int day ) {
              String ret = "";
              switch ( day ) {
                   case 1:
                        ret = "st";
                        break;
                   case 2:
                        ret = "nd";
                        break;
                   case 3:
                        ret = "rd";
                        break;
                   case 21:
                        ret = "st";
                        break;
                   case 22:
                        ret = "nd";
                        break;
                   case 23:
                        ret = "rd";
                        break;
                   case 31:
                        ret = "st";
                        break;
                   default:
                        ret = "th"; // everything else
              return ret;
    }Edited by: aaronabaci on Jan 6, 2008 9:49 PM

  • Can't dispose my dialog after moving it using swing timer.

    Hi all,
    I use the swing timer to move a dialog from one position to another. Here is the code I have use.
    // Set the main window display location
        public void setWindowLocation()
            int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
            int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
            int frameHeight = this.getHeight();
            int frameWidth = this.getWidth();
            int _xValue = (screenWidth - frameWidth);
            int _yValue = (screenHeight - getTrayheight() );
            int _yEnd = (screenHeight - frameHeight - getTrayheight() );
            //this.setLocation((screenWidth - frameWidth), (screenHeight - frameHeight - getTrayheight() - WINDOW_SPACE));
            this.setLocation(_xValue, _yValue);
            while(_yValue > _yEnd){
                dialogMotion(this, _xValue, _yValue);
                _yValue -= 1;
            // this.dispose();
    // Dialog motion
        private void dialogMotion(final MainDialog mainDialog, final int x, final int y){
            AbstractAction abAction = new AbstractAction() {
                public void actionPerformed(ActionEvent evnt) {
                    mainDialog.setLocation(x, y);
            Timer motionTimer = new Timer(300, abAction);
            motionTimer.setRepeats(false);
            motionTimer.start();
    // Find the taskbar height to place the main frame in lower-right corner
    // of the viewable area of the screen.
        private static int getTrayheight(){
            return (Toolkit.getDefaultToolkit().getScreenSize().height -
                     GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height);
        }I think my code is clear to you. After moving the dialog onto the task bar, I want to dispose it. You can see that at the end of the while loop I've try it.
    What happened there is, I can't see the dialog moving. it directly dispose. I add a breakpoint at the while loop and check, it iterate until condition is false. But I can't see the motion. If I comment the dispose code line as in my above code, I can see it moving.
    Why is that. Your comment really helpful to me.
    I'm worried is that debugging iterate that while loop but it is not visible. :( :(

    Thanks a lot. I got the point all of you said. But it is bit confusing how to do it.
    As i said in my first post, used slightly similar code to move down the dialog. Here what I have try. But the question is because of my thread used there, it wait little amount to scroll down.
        private void hideWindow(MainDialog mainGialog){
            try{
                int _xAbove = mainGialog.getLocation().x;
                int _yAbove = mainGialog.getLocation().y;
                int _yBelow = mainGialog.getLocation().y + mainGialog.getHeight() + getTrayheight();
                while(_yBelow > _yAbove){
                    dialogScrollingUpDown(this, _xAbove, _yAbove);
                    _yAbove += 1;
                Thread.sleep(1000);
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        try {
                            Thread.sleep(1500);
                            dispose();
                        catch (InterruptedException e) {
                            e.printStackTrace();
            catch (Exception ex) {
                System.out.println(ex.getMessage());
        private void dialogScrollingUpDown(final MainDialog mainDialog, final int x, final int y){
            AbstractAction abAction = new AbstractAction() {
                public void actionPerformed(ActionEvent evnt) {
                    mainDialog.setLocation(x, y);
            Timer motionTimer = new Timer(400, abAction);
            motionTimer.setRepeats(false);
            motionTimer.start();
    // System tray height
        private static int getTrayheight(){
            return (Toolkit.getDefaultToolkit().getScreenSize().height -
                     GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height);
        }Actually I called the hideWindow method in a button clicked event. After clicked the button, it wait a time equal to the first thread sleep. I can't reduce the time, if so dialog dispose instant.
    Whay I can't do all those things is my IDE not allowed to use frequently changing values in dialogScrollingUpDown method. You can see that in my code.
    Any comments for that.

  • Print out of time stamp ( time recording) in DBM ( using cats)

    Hello,
    in DBM we use standard time recording, everytime we post time stamp the system prints output of the time stamp
    we want to stop it...however is probobly control in HR . Any hints where?
    we use cac1 profile
    thanks!!!

    Mitch_Peplow wrote:
    Hi chembo,
    I'm not sure if I've misunderstood your answer but currently I'm not writing the time with am/pm anyway, its purely HH:MMS.MS and the data is there in Excel, it's just formatted the cell in an alternative way to what I would like.
    Cheers again
    Mitch
    I was thinking about something like the snipped added below. My version is very simple, but I think that it shows how it can be done. You need to have Excel on your machine. (Disclaimer: This is my very first use of the Report Generation Toolkit in LabVIEW, so maybe there is a better way to do it)
    I made the VI labels visible, so that you know what function was used, if the Toolkit is not included in your LabVIEW license. The same thing can be done with ActiveX automation. If you are not familiar with it, there are a lot of examples in the forums about generating Excel files via ActiveX.
    Edit: Attached is the Excel file generated from this code
    Attachments:
    milliseconds.xlsx ‏11 KB

  • How to kill all swing.Timer(s) at end of App

    I am using a javax.swing.Timer to cause text to flash in the text field. However, I noticed that if this timer is running when I stop my app, the timer's thread is still running. It appears that the class that has the timer is not being garbage collected immediately upon application exit. Is there a way to kill all swing timers?
    Thanks,
    John

    No. This is a class whose implementation I was hoping the main application would not have to know about. I was hoping that since I was using swing timers that when the application on which thread the swing timers are executing exited, all the swing timers attached to that application would be stopped.
    Do you have a suggestion how I might be able to do this? I have an application "A" that uses a library class "B" method that happens to start a timer. I do not want "A" to have to explicitly stop "B" when the application is ending. Is there a way I can tag the timer so that it will stop when "A" exits? Or could I somehow link "B" to "A" so that a dispose method on "B" is called when "A" exits or disposes?
    Thanks,
    John

Maybe you are looking for

  • How to make Adobe as your default viewer for all your PDF file instead of the Preview given? Thanks

    How to make Adobe as your default viewer for all your PDF file instead of the Preview given? Thanks

  • Screen flickers while using external display

    while using my macbook pro with an external display (my sony LCD TV). the external screen (TV) flickers. it goes black for about a second then comes on. it will happen about 20 minutes into watching TV and happens more often the longer i watch. for e

  • How do I put pictures on my ipod?

    Hello. I was wondering how I could put my pictures on my computer to my Ipod.   Windows XP Pro  

  • How to create triggers...

    I have the following trigger which seems to be working properly when it's created using sqlplus. CREATE OR REPLACE TRIGGER trig_address BEFORE INSERT ON address REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT seq_address.nextval INTO :NEW.ID FROM du

  • Dropped ipod/buying cases

    m thinking about buying a 20 dollar leather case for my ipod but i already dropped it 3 times before finally deciding to buy a case im worried that even though buying a case will guard against future drops, but the damage is already done and it would