Accueil > > > CHRONOMETER
CHRONOMETER
Information sur la source
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();
}
}
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
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
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
|
Derniers Blogs
GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|