Class Confetti

java.lang.Object
com.codename1.components.Confetti
All Implemented Interfaces:
Animation, Painter

public final class Confetti extends Object implements Painter, Animation

A burst of confetti over the whole form, for celebrating a finished task.

Form form = new Form("Done", BoxLayout.y());
Button finish = new Button("Finish");
finish.addActionListener(e -> Confetti.burst(form));
form.add(finish);
form.show();

The pieces are painted in the form's glass pane, so they cover everything and take no touches. They shoot up from the bottom center, flutter down and are gone after about three seconds, when the glass pane the form had before is put back.

  • Method Details

    • burst

      public static Confetti burst(Form form)

      Shoots 120 pieces of confetti over a form.

      Parameters
      • form: the form to cover
      Returns

      the burst, which removes itself when it ends

    • burst

      public static Confetti burst(Form form, int count)

      Shoots confetti over a form.

      Parameters
      • form: the form to cover
      • count: the number of pieces
      Returns

      the burst, which removes itself when it ends

    • getParticleCount

      public int getParticleCount()
      The number of pieces.
    • isFinished

      public boolean isFinished()
      True once the burst has ended and removed itself.
    • stop

      public void stop()
      Ends the burst at once.
    • animate

      public boolean animate()
      Description copied from interface: Animation

      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
    • paint

      public void paint(Graphics g)
      Description copied from interface: Animation

      Draws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.

      Parameters
      • g: graphics context
      Specified by:
      paint in interface Animation
    • paint

      public void paint(Graphics g, Rectangle rect)
      Description copied from interface: Painter

      Draws inside the given rectangle clipping area.

      Parameters
      • g: the Graphics object

      • rect: the given rectangle cliping area

      Specified by:
      paint in interface Painter