import processing.core.*; import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; import javax.sound.midi.*; import javax.sound.midi.spi.*; import javax.sound.sampled.*; import javax.sound.sampled.spi.*; import java.util.regex.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.sax.*; import javax.xml.transform.stream.*; import org.xml.sax.*; import org.xml.sax.ext.*; import org.xml.sax.helpers.*; public class JOTA2_12_revised extends PApplet {/*Jeremy Turner (JOT) Assignment A2-12 #200024742 Create a button that changes the color of the background when it is clicked.*/ int x = 11; int y = 11; int w = 333; int h = 333; //w = width (connects with X axis of shape) //h - height (connects with Y axis of shape) public void setup () { size (666, 666); } public void draw () { smooth (); strokeWeight(10); //this border makes the square... //...look more like a button. PFont font; font = loadFont("FrenchScriptMT-48.vlw"); //I uploaded this font using the "create font" feature... //The font is a bit corny but it seems to make all of the... //string characters visible... textFont(font); String s = "click on this square!!"; //this is the text that appears on the screen. fill(0,255, 104); //Sets the colour of the text and the square. text(s, 100, 370, 70, 70); //Sets the position of the text myButton(); //here is where I draw up my button... //that was previous stored in the function call //...below... } public void myButton () //this is the function call that defines... //the properties of my button... { rect(x,y,w,h); //draws a rectangle according to the ints set above... } public void mousePressed () { if (mouseX >= 11 && mouseX <=333 && mouseY >=11 && mouseY <=333) // This defines where on the X and Y axis the active button //...region is...the background changes once it the mouse button //...has been released. { background (random(100), random (100), random (100)); //I have decided to limit the random colour palette... //in order to produce a better colour contrast. } } static public void main(String args[]) { PApplet.main(new String[] { "JOTA2_12_revised" }); }}