import SpringGUI.*; /* This uses the "returnPressed" event of a TextField to add whatever content was in the TextField to a Choice element, as long as the content is not already an item in the Choice and the TextField is not empty. Selecting an item from the Choice will transfer it to the TextField. */ SpringGUI gui; // This is our instance of SpringGUI on which we will call all GUI related methods. void setup() { size(240,150); // canvas size... background(0,0,0); // clear the screen; gui = new SpringGUI(this); // <--- this line MUST be placed before gui can be used. gui.addTextField("myTextField", "Change and press return.", 10, 10, 180, 25); // create a TextField gui.addChoice("myChoice", 10, 40, 180, 25); // create a Choice } void draw() { } // this method is called whenever an event takes place: void handleEvent(String[] parameters) { // When return is pressed... if ( parameters[1].equals("myTextField") && parameters[2].equals("returnPressed") ) { // get the contents of the TextField: String txt = gui.getText("myTextField"); // if the txt is not empty and not part of the Choice... if ( !txt.equals("") && !gui.hasItem("myChoice",txt) ) { // add txt to the Choice as item. gui.addItem("myChoice", txt); } // empty the TextField gui.setText("myTextField", ""); } // If an item is selected... if ( parameters[1].equals("myChoice") && parameters[2].equals("selected") ) { // get the selected item... String item = gui.getSelectedItem("myChoice"); // set the TextField to the item... gui.setText("myTextField", item); } }