Guichronometer

Contenu du snippet

Une extension de JLabel permettant l'affichage des valeurs de la classe Chronometer

Source / Exemple :


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 javax.swing.JLabel; /**
  • Title:
  • Description:
  • Copyright: Copyright (c) 2001
  • Company: David Rolland, infodavid@chez.com
  • @author David Rolland, infodavid@chez.com
  • @version 1
  • /
public class GuiChronometer extends Chronometer implements Runnable { private JLabel label = null; private boolean paint = true; private boolean showSeconds = true; public boolean paintSeconds() { return showSeconds; } public boolean paintText() { return paint; } public void setTextPainted(boolean b) { paint = b; } public void setSecondsPainted(boolean b) { showSeconds = b; } public void setLabel(JLabel _label) { label = _label; } public JLabel getLabel() { return label; } private String getString(int i) { if (i < 10) { return "0" + i; } else { return String.valueOf(i); } } public void setText(String s) { if (getLabel() != null) { getLabel().setText(s); } } public String getText() { int[] time = getTime(); String t = time[0] + ":" + getString(time[1]); if (paintSeconds()) { t += ":" + getString(time[2]); } return t; } public void setText() { getLabel().setText(getText()); getLabel().repaint(); } public void run() { try { while (isAlive ()) { if (paintText() && getLabel() != null) { setText(); } Thread.sleep(getDelay()); increment(); } } catch (InterruptedException e) { } } }

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.

Du même auteur (cs_trap)