Home Ask Login Register

Developers Planet

Your answer is one click away!

Cmbone February 2016

Processing/PApplet Show or hide a figure based on clicking the mouse

Screenshot of the GUI

Hi guys. I am a newbie programmer and learning Java with processing.core.PApplet on Eclipse. The project visualizes Earthquakes/Majors Cities/Airports on the google Map. I created a "Control Window" which allows users to toggle on or off markers when they click the square box next to the text. Now my problem is, I want the "green check mark" to show inside the box when user clicks it and vanish when user clicks it again, but I don't know how to do it. Thank you.

Note: The major methods I have are setUp() ,draw(), mouseClicked() and mouseMoved(). All text,rect, and the check mark was drawn in draw() method. I use the MouseClicked() method to check whether the location where the cursor clicked is inside the box.


Kevin Workman February 2016

Just use a boolean variable that stores whether the checkbox should be drawn. Here's a little example:

boolean checked = false;

void mouseClicked(){
  checked = !checked;

void draw() {


  if (checked) {
    ellipse(50, 50, 20, 20);

You might also try using a GUI library like G4P, which has a checkbox component you can use instead of drawing it yourself.

Post Status

Asked in February 2016
Viewed 2,049 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life