How to resolve the algorithm Simple windowed application step by step in the Processing programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Simple windowed application step by step in the Processing programming language

Table of Contents

Problem Statement

Create a window that has:

Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Simple windowed application step by step in the Processing programming language

Source code in the processing programming language

//Aamrun, 11th July 2022

int labelLeft = 100, labelTop = 100, labelWidth = 440, labelHeight = 100;

int labelTextLeft = 150, labelTextTop = 150;

int buttonLeft = 170, buttonTop = 230, buttonWidth = 300, buttonHeight = 100;

boolean hasBeenClicked = false;

int clicks = 0;


void setup(){
  size(640,480);
  fill(255);
  rect(labelLeft,labelTop,labelWidth,labelHeight);
  fill(0);
  textSize(30);
  text("There have been no clicks yet",labelTextLeft,labelTextTop);
  fill(#c0c0c0);
  rect(buttonLeft,buttonTop,buttonWidth,buttonHeight);
  fill(0);
  text("Click Me !", buttonLeft + 50,buttonTop + 50);
}

void mousePressed(){
  if(mouseX > buttonLeft && mouseX < buttonLeft + buttonWidth
      && mouseY > buttonTop && mouseY < buttonTop + buttonHeight){
        hasBeenClicked = true;
        clicks++;
      }
}

void draw(){
  if(hasBeenClicked == true){
    fill(255);
    rect(labelLeft,labelTop,labelWidth,labelHeight);
    fill(0);
    textSize(30);
    text("Clicks : " + str(clicks),labelTextLeft,labelTextTop);
  }
}


  

You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the zkl programming language
You may also check:How to resolve the algorithm Lucas-Lehmer test step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the Draco programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the Swift programming language
You may also check:How to resolve the algorithm Fairshare between two and more step by step in the Delphi programming language