28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12 ■ Setting Boundaries for Your Action Figure in 2D: Using the Node Class LocalToParent Attribute<br />

This time, we are going to use the NetBeans Generate Getters and Setters dialog, which is shown in Figure 12-2, to<br />

selectively write the getters (the .is() methods) and the setters (the .set() methods), which will access the four Boolean<br />

variables. Technically, right now we only need to use the getter .is() methods, so you could use the Generate ➤ Getter<br />

menu option, shown in the middle (pop-up or floating) Generate menu, above the selected Getter and Setter option,<br />

in the middle (encased with a red line) of Figure 12-2. I prefer to generate both of these method “directions,” just in<br />

case, later on in the software development process, I need to set these variables (externally, in another class) for some<br />

programming reason relating to the game play logic development.<br />

Figure 12-2. Use the Source ➤ Insert Code ➤ Getter and Setter dialog to create methods for the four boolean variables<br />

Select the four Boolean down, left, right, and up variables in the Generate Getters and Setters dialog, shown on<br />

the far right side of Figure 12-2, click your cursor so that it is in front of the final } curly brace in your class (this will<br />

tell NetBeans that you want it to write, or place, this code at the end of the current class structure), and then click the<br />

Generate button at the bottom of this dialog, to generate the eight new Boolean variable access method structures.<br />

As you can see in Figure 12-3, there are eight new methods at the bottom of your InvinciBagel.java class. It is<br />

important to note that the .set() methods all use the <strong>Java</strong> this keyword to set the Boolean variable that you pass in to<br />

the method to the up, down, left, or right (private) variables. The .setUp() method, for instance, would look like this:<br />

public void setUp(boolean up) {<br />

this.up = up;<br />

}<br />

www.it-ebooks.info<br />

253

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!