Text input for choosing Colour

can also use a text edit field from a library like G4P

a shorter example:

/**
 GTextField  for Processing V2 and V3
 (c) 2015 Peter Lager
 */

import g4p_controls.*;

GTextField txf1;

public void setup() {
  size(500, 300);
  G4P.setGlobalColorScheme(GCScheme.PURPLE_SCHEME);
  txf1 = new GTextField(this, 10, 10, 80, 20);
  txf1.tag = "txf1";
  txf1.setPromptText("col HEX,NO #");

}

public void draw() {
  background(200, 128, 200);
}

public void displayEvent(String name, GEvent event) {
  String extra = " event fired at " + millis() / 1000.0 + "s";
  print(name + "   ");
  switch(event) {
  case CHANGED:
    println("CHANGED " + extra);
    break;
  case SELECTION_CHANGED:
    println("SELECTION_CHANGED " + extra);
    break;
  case LOST_FOCUS:
    println("LOST_FOCUS " + extra);
    break;
  case GETS_FOCUS:
    println("GETS_FOCUS " + extra);
    break;
  case ENTERED:
    println("ENTERED " + extra);
    println(" here do something ");
    break;
  default:
    println("UNKNOWN " + extra);
  }
}

public void handleTextEvents(GEditableTextControl textControl, GEvent event) { 
  displayEvent(textControl.tag, event);
}

1 Like