<< Chapter < Page | Chapter >> Page > |
Listing 12 also signals the end of the constructor for the class named ImgMod29 .
We have finally gotten to the fun part of the program. This is the part where we write the code that determines how the surface elevations and the calibrationscale values are displayed. This part of the program consists of six different inner classes.
The fact that the classes are inner classes makes it possible for methods in the class to access instance variables and methods of the containing object oftype ImgMod29 . This makes the programming somewhat easier than would be the case if they were all top-level classes.
Each of the six inner classes is a subclass of the class named Canvas and each of the classes overrides the paint method. The code in the overridden paint methods for the classes that display the 3D surfaces
The names and behaviors of three of those three classes are:
Associated directly with the three above classes are three other inner classes that are used to display the calibration scale immediately below theplot of the 3D surface. The names and behaviors of those three classes are:
Before getting into the details of these inner classes, however, I will present and briefly discuss a method named getCenter , which is called by the constructor for each of the surface plotting classes.
The getCenter method is used to find the horizontal and vertical center of the surface. These values are used to position the optionalred axes that may be drawn on the surface. This method is shown in its entirety in Listing 13 .
Listing 13. The method named getCenter. |
---|
int horizCenter;
int vertCenter;void getCenter(){
if(dataWidth%2 == 0){//evenhorizCenter =
dataWidth * blockSize/2 + blockSize/2;}else{//odd
horizCenter = dataWidth * blockSize/2;}//end elseif(dataHeight%2 == 0){//even
vertCenter =dataHeight * blockSize/2 + blockSize/2;
}else{//oddvertCenter = dataHeight * blockSize/2;
}//end else}//end getCenter |
Note that the returned values depend on whether the dimensions of the surface are even or odd.
(For example, the center of a string of five blocks of pixels is the third block whereas the center of a string of six blocks of pixels is halfway between the third and fourth blocks.)
Now that you know about the difference between even and odd surface dimensions, the code in Listing 13 should be straightforward and should not require further discussion.
Listing 14 shows the beginning of the class named CanvasType0surface and also shows the entire constructor for that class.
Notification Switch
Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?