WORKING WITH OBJECTS

by David de Almeida Bezerra Júnior


Java is an Object-oriented language, so, we have to work with objects. Below, there is a simple explanation about how work with objects on TetrisIDE.

If you do not know the object-oriented paradigm, take a look here.


Objects on TetrisIDE

Visually, you can add objects in the project's window by the Object Palette, selecting an object and clicking in the window on Desktop.

This time, we will develop a sum calculator, providing us understand how to manipulate object's properties.

Create a project named SumCalculator and change the property Title, width and height to Sum Calculator, 300 and 250, respectively from JFrameMain.



Adding objects



Add 3 Labels, 3 TextFields and 1 Button from Object Palette.

Change the property Text of the jLabel1, jLabel2, jLabel3 to Num1, Num2 and Result, respectively and change the names of jTextField1, jTextField2 and jTextField3 to jTextFieldNum1, jTextFieldNum2 and jTextFieldResult and erase the property Text. Change the property Text of the jButton1 to SUM.


Click and Sum


Select jButton1 and go to Events tab in the Object Inspector. Perform double click on OnClick event.



Select changeValue function in the Function field and write on Parameters:
jTextFieldResult
Text
"+(Double.parseDouble(jTextFieldNum1.getText())+Double.parseDouble(jTextFieldNum2.getText()))+"

Note that we use the method parseDouble of the class Double to transform the value of the type text, on Text property of the TextFields, to decimal numbers , showing that we can work with Java code within our applications.

Add (+) the function and press the OK button.
Save and Run the application.





CopyRight © 2017 Analisa Software.All Rights Reserved.