<< Chapter < Page | Chapter >> Page > |
Fifteen of the data values for each data set are not random for the same reasons discussed earlier. Figure 3 shows how these specific values confirm proper transition from one trace to the next on the same page and confirm theproper transition from one page to the next.
The first code that I will highlight as being different from the code in the class named PlotALot02 is shown in Listing 33 . This code appears in the modified constructor for the PlotALot03 class.
Listing 33. Modified constructor code. |
---|
if((tracesPerPage == 0) ||
(tracesPerPage%2 != 0) ){System.out.println("Terminating program");
System.exit(0);}//end if
samplesPerPage = canvasWidth * tracesPerPage/(sampSpacing + 1)/2; |
The if statement in Listing 33 confirms that the number of traces per page is evenly divisible by two. If not, the program terminates.
The last statement in Listing 33 computes the value of samplesPerPage taking into account that only half as many samples from each data set can beplotted on a page as is the case when the plots of the two data sets are superimposed on the same axes in the class named PlotALot02 .
Additional code that I will highlight as being different is in the overridden paint method of the MyCanvas class. This code is shown in Listing 34 .
Listing 34. The overridden paint method. |
---|
public void paint(Graphics g){
//Draw horizontal axes//...code deleted for brevity//Plot the points
if(sampleCounter>0){
for(int cnt = 0;cnt<= sampleCounter;
cnt++){//Plot values from the blackData// array object.
g.setColor(Color.BLACK);//Compute a vertical offset to locate// the black data on the odd numbered
// axes on the page.int yOffset =
((1 + cnt*(sampSpacing + 1)/this.getWidth())*2*traceSpacing)
- traceSpacing;//Draw an oval
//...code deleted for brevity//Connect the sample values with
// straight lines.//...code deleted for brevity//Plot the data stored in the
// redData array object.g.setColor(Color.RED);
//Compute a vertical offset to locate// the red data on the even numbered
// axes on the page.yOffset = (1 + cnt*(sampSpacing + 1)/
this.getWidth())*2*traceSpacing;//Draw the ovals//...code deleted for brevity
//Connect the sample values with// straight lines
//...code deleted for brevity}//end for loop
}//end if for sampleCounter>0
}//end overridden paint method}//end inner class MyCanvas
}//end inner class Page}//end class PlotALot02 |
Most of the code in the overridden paint method is the same as the code that I discussed earlier and was deleted from Listing 34 for brevity.
The code that is different is the code that computes the vertical offset values to locate the black data on the odd numbered axes and to locate the reddata on the even numbered axes as shown in Figure 3 . I will let you work through the expressions in Listing 34 on your own and convince yourself that the code is correct.
Notification Switch
Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?