by David de Almeida Bezerra Júnior

We will discuss about how to work with variables and procedures on TetrisIDE. To understand, We will build a program that, for each click in a button, increases a value to a integer variable and shows the result in a label.

What is Variables and Procedures?

A variable is an element on memory that contains a data that can change any time in code.
variable name="David";
write("My name is "+name); //The result is: My name is David
write("Now, my name is "+name); //The result is: Now, my name is Junior

A procedure is a block of code that executes a task and can be called in any part of the application. Very helpful when we will repeat the same function many times on program. So, just call the procedure.

Creating New Project

Press the New button, on Toolbar. Create a project named ClickCount.

Perform double click on property Title (Object Inspector) and modify to ClickCount.

Select the Label on Object Palette and click on window (Desktop). Do the same with a Button. Change the names to jLabelCount and jButtonCount, respectively. Change the Text of jButtonCount to Count.

Add an object Variable and a Procedure. Both elements are not visual, so, they will not appear on your application when it runs.

Change the name, Type and Value of Variable to count, int and 0. Change the name of the Procedure to addCount.

Adding Functions

On procedure, perform double click in the OnExecute event.

Select the function changeValue (Function field) and type on Parameters field:


The first parameter (getJFrameMain()) says where comes the property or variable changed. Every window on TetrisIDE has a method that returns itself. This method is formed by get+(window's name)+().
Second parameter (count) is the property or variable that will suffer the change.
The third parameter (getcount()+1) is the value received by the property or variable. Note the method getcount() is called and increased by 1. All variables on window have a get and set method.

Add another function changeValue with the Parameters:

jLabelCount //Object jLabel on window
Text //Property Text to modify
Count: "+getcount()+" //The result will be: "Count: (variable count's value)"

After the two functions added, press OK.

In the OnShow event, perform double click and add the function runProcedure with Parameter:

addCount //Object Procedure on window

Do the same with OnClick event of the jButtonCount.

Save and Run your application, clicking on buttons on Toolbar ou typing CTRL + S and F9.

CopyRight © 2023 Analisa Software.All Rights Reserved.