Now let's do some coding!
On the left side of Eclipse is the Package Explorer. Right Click on the HiLoGameClass (Just below HiLoGame.java) and select "Open With" -> "Form Editor". This will show you how the program will look.
What we need to do though is start editing the code. While we have been creating the UI, the java code has been generated for us by Jigloo.
From the Package Explorer reselect the HiLoGame object and Open With Java Editor. This is the code behind the program!
On the right side of the screen is the Outline of the program. Select the HiLoGame Object. Just inside the scope of the class are several private fields. Such as guessLabel, outputLabel, doneButton and guessText. Jigloo created these for us. Make a new line just below the last private field and type in "private int randomNumber = 0;"
Note that every command must end with a semi colon. What this line does is define a new variable that our program will use. "private" means that it is only accessible within our program. No other program can access this variable. int is a whole number. It is the type of variable we are working with. int stands for "integer". Our program needs to keep track of a random number between 1 and 100. So we need to define that variable in the program. That's what this line does. We first create the variable and assign it to zero.
A concept that you need to understand is what null means. null means nothing. There is a difference between null and zero. Null has no value. It really means nothing. Zero is a real value. If you don't have a bank account, then the total amount of money you have in the bank is "null". But if you have a bank account and you're broke, the total amount in your account is zero. Do you understand the difference? Let's talk if you don't.
So what we did is create the variable that will store this random number and initialize it to zero. ints are a primitive data type which means that it cannot be initialized to null. It has to have something in it, so let's just set it to zero.
Now let's generate a random number and put the value into this randomNumber variable:
super();
initGUI();
Under initGUI(); line enter "randomNumber = (int)(Math.random() * 100);"
Go ahead and run the program and you should see in your Eclipse console something like this:
Random number is: 57
Close your program and rerun it. You should see the console regenerated a new random number. Let's stop there for this week. That is alot of stuff to soak in. Please call me if you have questions so that you can better understand.
If you have questions please email me!