/* built with Studio Sketchpad: * http://sketchpad.cc * * observe the evolution of this sketch: * http://studio.sketchpad.cc/sp/pad/view/ro.J$kC-dnhokq/rev.7 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * http://creativecommons.org/licenses/by-sa/3.0/ */ /** * No Repeat ID Input (v2.0) * by GoToLoop (2015/Sep/15) * * Forum.Processing.org/two/discussion/12532/ * windowjs-cross-mode-alert-confirm-prompt-other-js-api-for-java#Item_2 * * Forum.Processing.org/two/discussion/869/check-array-contents-with-arraylist * * Bl.ocks.org/GoToLoop/8017bc38b8c8e0a5b70b * Studio.ProcessingTogether.com/sp/pad/export/ro.9$Bjf6i21oXBw */ import js.window; import java.util.List; final List<String> ids = new ArrayList<String>(); { for (String s : window.Array("alert()", "confirm()", "prompt()")) ids.add(s); } void draw() { for (String id : ids) print(id + " "); println(" "); final String id = window.prompt("Please enter new ID"); if (id == null) exit(); else if (id.length() == 0) window.alert("Empty ID Input!!!"); else if (ids.contains(id)) window.alert("ID \"" + id + "\" exists already!"); else { window.alert("ID \"" + id + "\" successfully added!!!"); ids.add(id); } }