PImageButton
Last updated
Last updated
The PImageButton class is a child-class of the Button class. The extends keyword in the first line of code in the class definition below shows the syntax for defining this class as a child-class of the Button class. As a child class, PImageButton inherits all properties and methods of the Button class.
To use the PImageButton class, you must first have an image in your project folder that you can use for displaying on the button.
Some newer versions of Processing don't require use of the data folder.
Use Menu: Sketch -> Add File.. The image below shows how to add an Image File to your Processing Project. When you select the Add File menu option, Processing will determine if the image needs to be in a separate data folder, or not. When using in your project, you will use code like the following:
PImage img1 = loadImage( "eraser.png");
//Filename must be in quotes.
Older Processing versions: Create data folder: For older versions of Processing, you must create a new folder inside your project folder with the name: data. See image below, which shows that 2 .png images have been added to the newly created data folder inside the project's sketch folder.
The images were created by taking screenshots of the canvas after the patterns had been drawn using the mouse.
PImageButtons shown on the Drawing Application You can adjust the dimensions of the image in the display( ) method in the PImageButton class, depending on the size of your buttons. The dimensions used in the code above work well for a button that is 100 px x 100 px.