|
Trouver une ressource
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
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
Sources en rapport avec celle ci
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
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|