Class BannerAd

java.lang.Object
All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class BannerAd extends Container

A banner ad that lives inside the Codename One component hierarchy. Add it to a form like any other component (typically anchored at the top or bottom) and call load():

BannerAd banner = new BannerAd("ca-app-pub-xxx/yyy");
form.add(BorderLayout.SOUTH, banner);
banner.load();

On a device the banner wraps the network's native ad view through a peer component; in the simulator it renders a labelled placeholder so layouts can be designed and tested without a device. The default SIZE_ADAPTIVE size asks the network for an anchored adaptive banner sized to the available width, which is the recommended modern banner type.

  • Field Details

    • SIZE_ADAPTIVE

      public static final int SIZE_ADAPTIVE
      Anchored adaptive banner sized to the available width (recommended).
      See Also:
    • SIZE_BANNER

      public static final int SIZE_BANNER
      Standard banner, 320x50.
      See Also:
    • SIZE_LARGE_BANNER

      public static final int SIZE_LARGE_BANNER
      Large banner, 320x100.
      See Also:
    • SIZE_MEDIUM_RECTANGLE

      public static final int SIZE_MEDIUM_RECTANGLE
      Medium rectangle, 300x250.
      See Also:
    • SIZE_LEADERBOARD

      public static final int SIZE_LEADERBOARD
      Leaderboard, 728x90 (tablets).
      See Also:
  • Constructor Details

    • BannerAd

      public BannerAd(String adUnitId)

      Creates an adaptive banner for the given ad unit id.

      Parameters
      • adUnitId: the ad unit identifier from the network console
    • BannerAd

      public BannerAd(String adUnitId, int size)

      Creates a banner of a specific size.

      Parameters
      • adUnitId: the ad unit identifier from the network console
      • size: one of the SIZE_* constants
  • Method Details

    • setAdListener

      public void setAdListener(AdListener listener)
      Sets the listener notified of this banner's lifecycle events.
    • load

      public void load()
      Loads a banner with default targeting.
    • load

      public void load(AdRequest request)

      Loads a banner using the supplied targeting metadata.

      Parameters
      • request: optional targeting metadata, may be null
    • dispose

      public void dispose()
      Releases the resources held by this banner. Call from your form's cleanup.