Java Led Ticker Component v2.0
www.ledticker.net

HowTo

Below are some snippets of Java code which displays various features of the Java Led Ticker Component.

  1. How to create a Led Ticker Component
  2. How to create a TickerElement and add/remove it to/from the LedTicker
  3. How to update a TickerElement
  4. How to customize the appearance of LedTicker
  5. How to control the aniamtion of the LedTicker
  6. How to control the animation speed of the LedTicker
    
    
  1. How to create a Led Ticker Component The code below shows how to create a LedTicker:
    LedTicker ledTicker = LedTickerFactory.createLedTicker();
    
  2. How to create a TickerElement and add/remove it to/from the LedTicker The code below shows how to create a TickerElement and add/remove it to/from the LedTicker. To remove an instance of TickerElement from the LedTicker, that instance must have been added first. Trying to remove an instance of TickerElement that was not previously added will generate an IllegalArgumentException. An useful method to remove all the elements at once is : ledTicker.removeAll();
    LedTicker ledTicker = LedTickerFactory.createLedTicker();
    TickerElement tickerElement1 = ... // an instance of some TickerElement implementation
    TickerElement tickerElement2 = ... // another instance of some TickerElement implementation
    TickerElement tickerElement3 = ... // another instance of some TickerElement implementation
    
    ledTicker.addElement(tickerElement1);
    ledTicker.addElement(tickerElement2);
    
    ledticker.removeElement(tickerElement1);
    
    // WRONG : 
    // tickerElement3 was never added to the ledTicker, so it cannot be removed.
    // An IllegalArgumentException will be thrown.
    ledTicker.removeElement(tickerElement3);
    
    tickerElement2 = ... // new instance of some TickerElement implementation
    
    // WRONG :
    // tickerElement2 now represents another instance of TickerElement that has never been added
    // to the ledTicker, therefore it cannot be removed.
    // An IllegalArgumentException will be thrown.
    ledTicker.removeElement(tickerElement2);
    
  3. How to update a TickerElement The code below shows how to update a TickerElement. To update an instance of TickerElement, that instance must have been first added to the LedTicker. Trying to update an instance of TickerElement that was not previously added will generate an IllegalArgumentException. An useful method to update all the elements at once is : ledTicker.updateAll();
    LedTicker ledTicker = LedTickerFactory.createLedTicker();
    
    TickerElement tickerElement1 = ... // an instance of some TickerElement implementation
    TickerElement tickerElement2 = ... // another instance of some TickerElement implementation
    TickerElement tickerElement3 = ... // another instance of some TickerElement implementation
    
    ledTicker.addElement(tickerElement1);
    
    // code to customize tickerElement1
    
    ledTicker.update(tickerElement1);
    
    // WRONG : 
    // tickerElement3 was never added to the ledTicker, so it cannot be updated.
    // An IllegalArgumentException will be thrown.
    ledTicker.updateElement(tickerElement3);
    
    tickerElement2 = ... // new instance of some TickerElement implementation
    
    // WRONG :
    // tickerElement2 now represents another instance of TickerElement that has never been added
    // to the ledTicker, therefore it cannot be updated.
    // An IllegalArgumentException will be thrown.
    ledTicker.updateElement(tickerElement2);
    
  4. How to customize the appearance of LedTicker The code below shows how the appearance of the LedTicker can be customized:
    LedTicker ledTicker = LedTickerFactory.createLedTicker();
    
    // Set the background color of the LedTicker
    ledTicker.setBackgroundColor(new Color(51, 51, 51));
    
    // Set the color of a turned off dot
    ledTicker.setDotOffColor(Color.BLACK);
    
    // Set the dimensions, in pixels, of the ticker's led
    // Default values are (1, 1). 
    ledTicker.setDotSize(2, 2);
    
    // Set the gaps, in pixels, between two ticker leds.
    // Default values are (1, 1). 
    ledTicker.setDotGaps(2, 2);]
    
    // Set the gap, in dots, between two elements of the ticker
    // Default value is 4.
    ledTicker.setElementGap(6);
    
    // Set the gap, in dots, between two tokens of an element.
    // Default value is 2.
    ledTicker.setTokenGap(4);
    
  5. How to control the animation of the LedTicker The following code shows how the animation of the LedTicker can be controlled:
    LedTicker ledTicker = LedTickerFactory.createLedTicker();
    
    // code to add instances of TickerElement to the LedTicker
    
    // Start the LedTicker scrolling
    ledTicker.startAnimation();
    
    // Pause the LedTicker scrolling
    // Note : 1.This method stops the animation without terminating it's associated Thread.
    //        2.A second consecutive call of this method will restart the animation.
    ledTicker.pauseAnimation();
    
    // Stop the ticker elements' scrolling.
    // This method terminates the Thread responsible with the ticker's animation.
    ledTicker.stopAnimation();
    
  6. How to control the animation speed of the LedTicker
    LedTicker ledTicker = LedTickerFactory.createLedTicker();
    
    // Set the speed of the ticker animation.
    // The speed must be a value between 1 and 10, default value is 3.
    ledTicker.setSpeed(5);