Appendix 2: Sample Code
This sample program searches Amazon for products in the Music section that match the term "Manilow", and searches Yahoo Images for "big bird", and flashes the resulting images on the screen.
import org.switchboard.*; Switchboard board; ArrayList images = new ArrayList(); void setup() { size(300, 300); framerate(10); // The switchboard will be our interface to all of the services. board = new Switchboard(this); // Some services require developer keys // Try running a query without setting the key to find out where to get one board.setAmazonKey("XXXXXXXXXXXXXXXXXXXXX"); board.setYahooKey("XXXXXXX"); // Here we are starting two services board.amazon("Music", "Manilow"); board.yahooImage("big bird"); } // Since we called both amazon and YahooImages, board.serviceClass is either // going to be Amazon.class or YahooImages.class. void resultReceived() { if(board.resultService == Switchboard.AMAZON) { // to get the image URL out of board.amazon, // the method is called getSmallImage() PImage img = loadImage(board.amazon.getImageUrlSmall()); images.add(img); } if(board.resultService == Switchboard.YAHOOIMAGE) { // to get the image URL out of board.yahooImages, // the method is called getUrl() PImage img = loadImage(board.yahooImage.getUrl()); images.add(img); } } void draw() { // Loop through all of the images we have collected and draw them. for(int i=0; i<images.size(); i++) { image((PImage)images.get(i), random(width), random(height)); } }