NoGroup Demo and Documentation

Display sketch code: NoGroupDemo.pde

While using a ClickableGroup is highly recommended, it is not absolutely necessary. This demo shows the coding that is needed if ClickableGroup is not used.

If one looks at the code, one sees that not using ClickableGroup causes the mouseReleased() method to become significantly more complicated than when a group is used. You will observe that in draw(), one needs to display each Clickable item. The code normally in updateGrp() has been replaced by the code in processAnyClicks().

In the mouseReleased() method, isOver() must be called for each Clickable item until the clicked item is found. If the mouse is over an item, then checkForClick() is called. When something is clicked, the drop down list of any ComboBox or Menu must be closed.

In the draw() method, the Button is drawn first because parts of it can be covered by the ComboBox. That means that in the mouseReleased() method, the ComboBox must be checked first.

  // Strings arrays for the ComboBox
  String[] cmbStrings = {"Combo A", "Combo B", "Combo C"};
  // Clickable items
  Button btn = new Button(25, 55, 90, 30, "Button",
                   #DDDDDD, #AAAAAA, #DDDD00, #AAAA00);
  ComboBox cmb = new ComboBox(25, 25, 90, cmbStrings,
                   #DDDDDD, #AAAAAA, #DDDD00, #AAAA00);
  ScrollSketch scrSketch;
  // Output string
  String msg;

  void setup() {
    size(320, 130);
    smooth();
    frameRate(20);
    msg = "Click some items";
  }  // setup

  void draw() {
    background(#FFFFAA);   // background color
    processAnyClicks();

    fill(#000000);
    text("NoGroup Demo", 146, 20);
    text(msg, 146, 75);
    btn.display();
    cmb.display();
  }  // draw

  void processAnyClicks() {
    if (btn.hasBeenClicked()) {
      msg = "The button was clicked";
    } else if (cmb.hasBeenClicked()) {
      if (cmb.getClickedItemNum() == cmb.COMBO_BUTTON)
        msg = "The combo button was clicked";
      else
        msg = "You clicked " + cmb.getSelectedItem().getLabel();
    }
  }  // processAnyClick

  void mouseReleased() {
    stillSearching_ = true;
    cmb.hideSomething(); // close the drop down list, if needed
    if (cmb.isOver())
      cmb.checkForClick();
    if (stillSearching_) {
      if (btn.isOver())
        btn.checkForClick();
    }
  }  // mouseReleased
Return to the top of the page

Revised: 04/11/2014