Java 8 Timer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Timer class.

This code example shows how to use the following methods:setRepeats, start
      else 
         setLocationRelativeTo(null); 
   } 
    
   public void setTimeout(int timeout){
      Timer timer = new Timer(timeout, new ActionListener(){
 
         @Override 
         public void actionPerformed(ActionEvent arg0) {
            command = null;
            dismiss(); 
         } 
          
      }); 
      timer.setRepeats(false);
      timer.start();
   } 
    
   void init(String text){
       
      setBackground(Color.yellow);
7
CodeRank
This code example shows how to use the following methods:setInitialDelay, setRepeats, start
glass.revalidate();
		glass.repaint();
		if (closeAfter) {
			if (timer == null) {
				timer = new Timer(500, new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						hideAnimation(); 
					} 
				}); //fire every half second 
				timer.setInitialDelay(2000); //first delay 2 seconds
				timer.setRepeats(false);
			} 
		    timer.start();
		} 
	} 
	 
	/** 
	 * Creates a new instance. 
	 *  
6
CodeRank
This code example shows how to use the following methods:setDelay, setInitialDelay, start, stop
				break; 
			case FAST_SPEED:
				delay = DELAY_FAST;
				break;	 
		} 
		timer.setDelay(delay);
	    timer.setInitialDelay(delay);
	} 
	 
	/**  
	 * Plays the slide show. 
	 *  
	 *  @param index 	The playing index,  
	 *  				either {@link #PLAY_FORWARD} or {@link #PLAY_BACKWARD}. 
	 */ 
	private void play(int index)
	{ 
		if (index == playingIndex) return;
		if (state == START) stop();
		playingIndex = index;

6
CodeRank
This code example shows how to use the following methods:setInitialDelay, start
     * or until close() is called explicitly. 
     */ 
    public void open(int nMilliseconds) {
        if (image_ == null) return;
         
        Timer timer = new Timer(Integer.MAX_VALUE, new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                ((Timer) event.getSource()).stop();
                close(); 
            }; 
        }); 
         
        timer.setInitialDelay(nMilliseconds);
        timer.start();
         
        setBounds(x_, y_, width_, height_);
        setVisible(true);
    } 
     
     
6
CodeRank
This code example shows how to use the following methods:setRepeats, start
    } 
 
    public static void highlightComponent(final JComponent c) {
        if (c.getBackground() == HIGHLIGHT) return; //prevent two timers
        c.setBackground(HIGHLIGHT);
        Timer t = new Timer(800, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                c.setBackground(null);
            } 
        }); 
        t.setRepeats(false);
        t.start();
    } 
 
    public static Color stringToColor(String colorName) {
        colorName = colorName.trim();
        if (colorName.startsWith("#")) {
            if (colorName.length() != 7) throw new  IllegalArgumentException("Invalid #RRGGBB sytnax: "+ colorName);
            //RGB format 
            int r = Integer.parseInt(colorName.substring(1,3),16);
6
CodeRank
This code example shows how to use the following methods:addActionListener, setRepeats
  public CompressedAlgebraView(AlgebraControllerD algCtrl, int updatesPerSecond,
      int repaintsPerSecond) {
    super(algCtrl);
    ups = updatesPerSecond;
    rps = repaintsPerSecond;
    updateTimer = new Timer(1000 / ups, null);
    updateTimer.setRepeats(false);
    repaintTimer = new Timer(1000 / rps, null);
    repaintTimer.setRepeats(false);
    updateSet = new HashSet<GeoElement>();
    updateListener = new CompressedUpdateListener(this, updateTimer, updateSet,
        lock);
    updateTimer.addActionListener(updateListener);
    repaintListener = new CompressedRepaintListener(this);
    repaintTimer.addActionListener(repaintListener);
    needRepaint = false;
  } 
 
  @Override 
  final public void update(GeoElement geo) {
6
CodeRank
This code example shows how to use the following methods:start
       timer = new Timer(timeout,this);
   } 
       
   public String waitForTransition(final TransitionListener listener){
      this.listener = listener;
      timer.start();
      return "Next"; 
   } 
 
   @Override 
   public void actionPerformed(ActionEvent arg0) {
      listener.transitionOccurred(this);
   }          
      
} 
 
 
6
CodeRank
This code example shows how to use the following methods:setCoalesce, setDelay, setInitialDelay, setRepeats
This code example shows how to use the following methods:setCoalesce, setInitialDelay
            throw new IllegalArgumentException("Model cannot be null.");
        this.model = model;
        state = -1;
        delay = DELAY;
        model.addChangeListener(this);
        timer = new Timer(DELAY, this);
        timer.setInitialDelay(DELAY/10);
        timer.setCoalesce(true);
    } 
 
    /** 
     * Sets the state of the player. 
     *  
     * @param state One of the constants defined by this class. 
     */ 
    public void setPlayerState(int state)
    { 
        switch (state) {
            case START:
            case STOP: 
6
CodeRank
This code example shows how to use the following methods:stop
          if (c != null){
             c.getParent().getParent().repaint(r1.x,r1.y,r1.width,r1.height);
          } 
          
      }else{ 
         timer.stop();
       
      }       
   } 
    
   public void start(){ 
      comp.setActualLocation(src.x,src.y);
      super.start(); 
   } 
    
   public void stop(){ 
      //comp.setLocation(dest.x,dest.y); 
      super.stop(); 
   } 
} 
5
CodeRank
See Code Examples for Java 8 Timer Methods: