input from users type?

edited June 2014 in How To...

Hi,

How would I get a typed input from user while processing is running?

Just like google's main pages type bar below image.

Screen Shot 2014-06-18 at 3.44.19 PM

Thank you,

Answers

  • I've got 2 models:

    Online: http://studio.processingtogether.com/sp/pad/export/ro.9Zo$UbIWYZEDR/latest
    And the 1 below:

    /**
     * No Repeat ID Input (v1.10)
     * by GoToLoop (2013/Nov)
     *
     * forum.processing.org/two/discussion/869
     * /check-array-contents-with-arraylist
     */
    
    import static javax.swing.JOptionPane.*;
    
    final StringList ids = new StringList( new String[] {
      "Eric", "Beth", "Katniss"
    }
    );
    
    void draw() {
      println(ids);
    
      final String id = showInputDialog("Please enter new ID");
    
      if (id == null)   exit();
    
      else if ("".equals(id))
        showMessageDialog(null, "Empty ID Input!!!",
        "Alert", ERROR_MESSAGE);
    
      else if (ids.hasValue(id))
        showMessageDialog(null, "ID \"" + id + "\" exists already!!!",
        "Alert", ERROR_MESSAGE);
    
      else {
        showMessageDialog(null, "ID \"" + id + "\" successfully added!!!",
        "Info", INFORMATION_MESSAGE);
    
        ids.append(id);
      }
    }
    
Sign In or Register to comment.