<< Chapter < Page | Chapter >> Page > |
Listing 16. Make all pages invisible. |
---|
Page tempPage = null;
for(int cnt = 0;cnt<(pageLinks.size());
cnt++){tempPage = pageLinks.get(cnt);
tempPage.setVisible(false);}//end for loop |
The code in Listing 17 iterates on the ArrayList object again, accessing the references to the Page objects in reverse order and setting the value of the visible property for each Page object to true. This results in page 0 (the page with the earliest data) being on the top of the stack.
Listing 17. Make the pages visible in reverse order. |
---|
for(int cnt = pageLinks.size() - 1;cnt>= 0;
cnt--){tempPage = pageLinks.get(cnt);
tempPage.setLocation(xCoor,yCoor);tempPage.setVisible(true);
}//end for loop}//end plotData(int xCoor,int yCoor) |
In addition, the code in Listing 17 sets the location property of each Page object to the coordinate values received as incoming parameters to the plotData method. This causes the stack of Page objects to appear in the specified location on the screen.
The other overloaded version of the plotData method is shown in its entirety in Listing 18 .
Listing 18. The other overloaded version of the plotData method. |
---|
void plotData(){
plotData(0,0);//call overloaded version}//end plotData() |
This version receives no incoming parameters. The body of the method simply calls the first overloaded version discussed above, passing coordinate values as0,0 as parameters. As explained earlier, this causes the stack of Page objects to appear in the upper left corner of the screen.
The Page class is a member class of the class named PlotALot01 . As such, methods belonging to objects of the Page class have direct access to all of the other members of the enclosing PlotALot01 object, including instance variables belonging to the PlotALot01 object.
(If you are unfamiliar with member classes, see the module titled The Essence of OOP using Java, Member Classes .)
A PlotALot01 object may own as many Page objects as are required to plot all of the data values that are fed to it.
(The reference to each Page object is stored in an ArrayList object belonging to the PlotALot01 object.)
The Page class, which extends the Frame class begins, in Listing 19 . The constructor for the Page class also begins in Listing 19 .
Listing 19. Beginning of the class named Page. |
---|
class Page extends Frame{
MyCanvas canvas;int sampleCounter;
Page(String title){//constructorcanvas = new MyCanvas();
add(canvas);setSize(frameWidth,frameHeight);
setTitle(title + " Page: " + pageCounter);setVisible(true); |
The Page class begins by declaring two instance variables. The instance variable named canvas will hold a reference to an object of the MyCanvas class upon which the data will actually be plotted.
The other instance variable will hold the value of a sample counter.
The constructor that begins in Listing 19 instantiates an object of a member class named MyCanvas and stores its reference in the reference variable named canvas . Then it adds the MyCanvas object to the default center location of the Page ( Frame ) .
Notification Switch
Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?