import SpringGUI.*; /* Four Radiobuttons let the user choose the background color for the Applet. Since the GUI elements in SpringGUI are not transparent, we will have to change their background as well. */ SpringGUI gui; // This is our instance of SpringGUI on which we will call all GUI related methods. // create four colors for the background color myRed = color(220, 70, 60), myBlue = color(100, 120, 220), myOrange = color(220, 180, 60), myPurple = color(120, 20, 110); void setup() { size(200,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.addRadiobutton("myRBN1", "red", "myGroup", 10, 10, 180, 20); // create a Radiobutton gui.addRadiobutton("myRBN2", "blue", "myGroup", 10, 30, 180, 20); // create a Radiobutton gui.addRadiobutton("myRBN3", "orange", "myGroup", 10, 50, 180, 20); // create a Radiobutton gui.addRadiobutton("myRBN4", "purple", "myGroup", 10, 70, 180, 20); // create a Radiobutton gui.setState("myRBN1", true); // select Radiobutton 1 background(myRed); // set the Applet's background gui.setAllBackgrounds(myRed); // set the backgrounds of the elements } void draw() { } // this method is called whenever an event takes place: void handleEvent(String[] parameters) { // When a Radiobutton is selected... if ( parameters[0].equals("Radiobutton") && parameters[2].equals("selected") ) { String selected = gui.getSelectedRadiobutton("myGroup"); // get the selected Radiobutton in our group if (selected.equals("myRBN1")) { // if it is Radiobutton 1 background(myRed); // set the Applet's background gui.setAllBackgrounds(myRed); // and the elements' backgrounds } else if (selected.equals("myRBN2")) { // if it is Radiobutton 2 background(myBlue); // set the Applet's background gui.setAllBackgrounds(myBlue); // and the elements' backgrounds } else if (selected.equals("myRBN3")) { // if it is Radiobutton 3 background(myOrange); // set the Applet's background gui.setAllBackgrounds(myOrange); // and the elements' backgrounds } else if (selected.equals("myRBN4")) { // if it is Radiobutton 4 background(myPurple); // set the Applet's background gui.setAllBackgrounds(myPurple); // and the elements' backgrounds } } }