Class TypewriterLabel

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Label
com.codename1.components.TypewriterLabel
All Implemented Interfaces:
Animation, Editable, StyleListener, IconHolder, TextHolder

public class TypewriterLabel extends Label

A label that types its text out a character at a time.

TypewriterLabel hello = new TypewriterLabel();
hello.setCharactersPerSecond(20);
hello.addCompletionListener(e -> Log.p("Done typing"));
hello.type("Welcome back!");

type(String) starts typing; setText still shows a text at once. skip() shows the rest straight away, for a user who taps to hurry it. The typing runs while the label is on a showing form.

  • Constructor Details

    • TypewriterLabel

      public TypewriterLabel()
      An empty label.
  • Method Details

    • type

      public void type(String text)

      Starts typing a text from its first character.

      Parameters
      • text: the text to type
    • getFullText

      public String getFullText()
      The whole text being typed.
    • isTyping

      public boolean isTyping()
      True while characters are left to type.
    • setCharactersPerSecond

      public void setCharactersPerSecond(int cps)

      Sets the typing speed; 30 characters a second by default.

      Parameters
      • cps: characters a second
    • skip

      public void skip()
      Shows the whole text at once.
    • addCompletionListener

      public void addCompletionListener(ActionListener l)

      Adds a listener told when the text is fully typed.

      Parameters
      • l: the listener
    • removeCompletionListener

      public void removeCompletionListener(ActionListener l)

      Removes a completion listener.

      Parameters
      • l: the listener
    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
      Overrides:
      deinitialize in class Component
    • animate

      public boolean animate()
      Description copied from class: Label

      Allows the animation to reduce "repaint" calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

      Returns

      true if a repaint is desired or false if no repaint is necessary

      Specified by:
      animate in interface Animation
      Overrides:
      animate in class Label