Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

CHRONOMETER


Information sur la source

Catégorie :Api Classé sous : chronomètre, intervalle, milliseconde, secondes Niveau : Débutant Date de création : 03/06/2002 Date de mise à jour : 03/06/2002 17:22:43 Vu : 8 135

Note :
Aucune note

Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

Description

Un chronomètre de plus avec spécification de l'intervalle de déclenchement en millisecondes.
 

Source

  • package com.infodavid.util;
  • /*
  • * Copyright (c) 2001 David Rolland
  • *
  • * Redistribution and use in source and binary forms, with or without
  • * modification, are permitted provided that the following conditions are met:
  • *
  • * -Redistributions of source code must retain the above copyright notice, this
  • * list of conditions and the following disclaimer.
  • *
  • * -Redistribution in binary form must reproduct the above copyright notice,
  • * this list of conditions and the following disclaimer in the documentation
  • * and/or other materials provided with the distribution.
  • *
  • * This software is provided "AS IS," without a warranty of any kind. ALL
  • * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  • * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  • * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. D.Rolland SHALL NOT BE
  • * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  • * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL D.Rolland
  • * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  • * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  • * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  • * OR INABILITY TO USE SOFTWARE, EVEN IF D.Rolland HAS BEEN ADVISED OF THE
  • * POSSIBILITY OF SUCH DAMAGES.
  • *
  • * You acknowledge that Software is not designed,licensed or intended for use in
  • * the design, construction, operation or maintenance of any nuclear facility.
  • */
  • import java.awt.event.ActionEvent;
  • import java.io.Serializable;
  • /**
  • * Title:
  • * Description:
  • * Copyright: Copyright (c) 2001
  • * Company: David Rolland, infodavid@chez.com
  • * @author David Rolland, infodavid@chez.com
  • * @version 1
  • */
  • public class Chronometer extends ListenedObjectImpl implements Runnable,
  • Serializable {
  • private Thread chronometre;
  • private float step = 0;
  • private long minutes = 0;
  • private int delay = 100;
  • public void reset() {
  • step = 0;
  • minutes = 0;
  • }
  • public void setDelay(int ms) { delay = ms; }
  • public int getDelay() { return delay; }
  • public void start() {
  • reset();
  • chronometre = new Thread (this);
  • chronometre.start();
  • }
  • public void cont() {
  • if (chronometre != null) {
  • chronometre.start();
  • }
  • else {
  • start();
  • }
  • }
  • public int[] getTime() {
  • int time[] = new int[4];
  • //heure
  • time[0] = (int)(minutes / 60);
  • //minute
  • time[1] = (int)(minutes % 60);
  • //seconde
  • time[2] = (int)(((step * delay) / 1000) % 60);
  • //dixieme
  • time[3] = (int)((step * delay) % 10);
  • return time;
  • }
  • protected boolean isAlive() {
  • if (chronometre != null) {
  • return chronometre.isAlive();
  • }
  • else {
  • return false;
  • }
  • }
  • protected void increment() {
  • step++;
  • final float minute = 60000 / (float)delay;
  • if (step >= minute) {
  • short i = (short)(step / minute);
  • minutes += i;
  • step -= i * minute;
  • }
  • raiseEvent(new ActionEvent(this, 0 , getClass().getName(), minutes, 0));
  • }
  • public void run() {
  • try {
  • while (isAlive()) {
  • Thread.sleep(getDelay());
  • increment();
  • }
  • } catch (InterruptedException e) { }
  • }
  • public void stop() {
  • if (isAlive()) {
  • chronometre.interrupt();
  • }
  • }
  • }
package com.infodavid.util;
/*
 * Copyright (c) 2001 David Rolland
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * -Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduct the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. D.Rolland SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL D.Rolland
 * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF D.Rolland HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that Software is not designed,licensed or intended for use in
 * the design, construction, operation or maintenance of any nuclear facility.
 */
import java.awt.event.ActionEvent;

import java.io.Serializable;
/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      David Rolland, infodavid@chez.com
 * @author       David Rolland, infodavid@chez.com
 * @version 1
 */
public class Chronometer extends ListenedObjectImpl implements Runnable,
  Serializable {

  private Thread chronometre;
  private float step = 0;
  private long minutes = 0;
  private int delay = 100;

  public void reset() {
    step = 0;
    minutes = 0;
  }

  public void setDelay(int ms) { delay = ms; }

  public int getDelay() { return delay; }

  public void start()  {
    reset();

    chronometre = new Thread (this);
    chronometre.start();
  }

  public void cont() {
    if (chronometre != null) {
      chronometre.start();
    }
    else {
      start();
    }
  }

  public int[] getTime() {
    int time[] = new int[4];

    //heure
    time[0] = (int)(minutes / 60);
    //minute
    time[1] = (int)(minutes % 60);
    //seconde
    time[2] = (int)(((step * delay) / 1000) % 60);
    //dixieme
    time[3] = (int)((step * delay) % 10);

    return time;
  }

  protected boolean isAlive() {
    if (chronometre != null) {
      return chronometre.isAlive();
    }
    else {
      return false;
    }
  }

  protected void increment() {
    step++;

    final float minute = 60000 / (float)delay;

    if (step >= minute) {
      short i = (short)(step / minute);

      minutes += i;

      step -= i * minute;
    }

    raiseEvent(new ActionEvent(this, 0 , getClass().getName(), minutes, 0));
  }

  public void run() {
    try {
      while (isAlive()) {
        Thread.sleep(getDelay());

        increment();
      }
    } catch (InterruptedException e) { }
  }

  public void stop() {
    if (isAlive()) {
      chronometre.interrupt();
    }
  }
}

Commentaires et avis

signaler à un administrateur
Commentaire de allo12345 le 09/07/2003 22:09:42

quelqun pourrait maider a comprendre ceci !!!

C:JAVAChronometer.java:7: cannot resolve symbol
symbol  : class ListenedObjectImpl
location: class com.infodavid.util.Chronometer
public class Chronometer extends ListenedObjectImpl implements Runnable,
                                 ^
C:JAVAChronometer.java:27: reference to Thread is ambiguous, both method Thread(java.lang.Runnable) in java.lang.Thread and method Thread(java.lang.String) in java.lang.Thread match
    chronometre = new Thread (this);
                  ^
C:JAVAChronometer.java:77: cannot resolve symbol
symbol  : method getClass ()
location: class com.infodavid.util.Chronometer
    raiseEvent(new ActionEvent(this, 0 , getClass().getName(), minutes, 0));
                                         ^
C:JAVAChronometer.java:77: cannot resolve symbol
symbol  : method raiseEvent (java.awt.event.ActionEvent)
location: class com.infodavid.util.Chronometer
    raiseEvent(new ActionEvent(this, 0 , getClass().getName(), minutes, 0));
    ^
4 errors

Tool completed with exit code 1

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

comment temporiser le lancement des video ? [ par good2 ] salut tout le monde, Voila j'aimerais savoir si c'est possible de temporiser le lancement des video ? Dans mon cas j'ai 3 video (video1, video2 et v date en secondes depuis 1er janvier 1970 [ par floorfille ] bonjour,voila mon pb, (qui ne doit pas en etre un pour ceux qui maitrise bien les formats date en java)je recupere des entiers correspondant a l'annee connexion JDBC [ par albator2004 ] Bonjour!!Voilà, j'ai créé une classe qui se conecte à une base oracle via jdbc selon le nom de la base passée en paramètre.Cependant, il se peut que l [MIDP] Réaliser un timer [ par heyhi ] Salut à tous.Je dévellope depuis peu de temp en java, pour embarquer sur téléphone portable. Et j'aurais besoin de réaliser u Execution d'une fonction toutes les X secondes ... [ par joebar3333 ] Bonjour à tous,j'aimerai qu'une de mes fonctions soit exécutée toutes les secondes. J'ai bien essayé de bidouiller avec System.cur Gestion d'une tache avec un temps inférieur à la milliseconde [ par bouban ] Bonjour,je désire commander un moteur pas a pas à l'aide du port parallèle. Il faut ecrire des 0 et des 1 en permanence sur une sortie Chronomètre [ par Never_Summer ] Bonjour,Ma nouvel question du jour,y a t'il un composant chronomètre avec java ??Si non comment pourrais-je en crée un ?Merci de vos ré Chronomètre [ par qhhu ] Salut Tout le monde !J'ai un problème avec un petit chronomètre que j'ai fabriqué.Quand j'appuie sur le bouton Start, il reste appuy&#2 Pb de timer.stop() [ par joduak ] Bonjour, J'ai un gros problème, je galère depuis longtemps étant débutant... J'ai lu la doc sur timer sur Sun, mais je n'arrive p date en milliseconde [ par amel2006 ] comment obtenir la difirence de miliseconde de deux date en millisecondeamel2006


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,952 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.