|
The first order of business for putting together the Color Belot application is to provide the necessary constants. In Java, an ideal way to provide a set of related constants is to put them in a construct called an interface. The complete interface is in a file called "BelotConstants.java". An explanation to understand this interface now follows. Following a file header comment, the code begins with the line "interface BelotConstants". The keyword "interface" indicates that this Java construct is an interface. The name of the interface is "BelotConstants". The interface extends from the opening left brace to the closing right brace. The first constant following the opening left brace is "public final static int NUMBER_OF_PLAYERS = 2;". Let's look at the components of this line. "public" indicates that this constant is available to any Java construct that uses this interface. "final" indicates that that value cannot be changed. "static" indicates that only one copy of this constant will be used. "int" indicates an integer. In Java, an int is always stored using 4 bytes. "NUMBER_OF_PLAYERS" is the name of the constant, and 2 is its value. By convention, constants in interfaces are given names with all capital letters. Now look at the line "public final static int [] VALUES = {0, 0, 10, 2, 3, 4, 11}". There are two new things to focus on in this line. First, "int []" indicates that "VALUES" is goings to be an array of integers. Second, "{0, 0, 10, 2, 3, 4, 11}" on the right hand side of the = sign constructs and initializes the array. In this case, the array has 7 elements. Position 0 contains a 0, position 1 contains a 0, position 2 contains a 10, etc. Take a look at the interface until you understand everything in it. If you need more assistance, take the following links:
|