Page 625 - Introduction to Programming with Java: A Problem Solving Approach
P. 625

                Figure 14.21b
Scalability
LinePlotPanel class—part B
14.13 GUI Track and Problem Solving: Line Plot Example Revisited (Optional) 591
 }
// end class LinePlotPanel
}
// end LinePlotPanel constructor
// Calculate integer pixel interval between adjacent points
pixelInterval = rectWidth / (numOfPoints - 1);
// Make rectangle's actual width = multiple of pixelInterval
rectwidth = (numOfPoints - 1) * pixelInterval;
xPixels = new int[numOfPoints];
yPixels = new int[numOfPoints];
for (int i=0; i<numOfPoints; i++)
{
}
xPixels[i] = topLeftX + (i * pixelInterval);
yPixels[i] = topLeftY + rectHeight - (int) Math.round(
(frame.getYCoords()[i] / frame.getMaxY()) * rectHeight);
//**********************************************************
// This class displays line as sequence of connected points.
  public void paintComponent(Graphics g)
{
precomputed parameters
super.paintCAopmpaongenot(g)P; DF Enhancer g.drawRect(topLeftX, topLeftY, rectWidth, rectHeight); ⎫
⎬ g.drawPolyline(xPixels, yPixels, xPixels.length); ⎭
 } // end paintComponent
A program is scalable if it’s able to support larger or smaller amounts of data and more or fewer users. The support for more data and more users might require changes to the software, but the changes should be cost- effective incremental add-ons, not massive rewrites.
A professional-grade line-plotting program should be able to handle large quantities of data and differ- ent types of data. Our LinePlotGUI program may not achieve that level of scalability (it handles only one type of data, and all the data must fit in one window), but it’s not too bad, considering that we needed to keep it reasonably short to fit in an introductory textbook. The LinePlotGUI program is scalable in that its scope is constrained primarily by user input and a few named constants, not by hard-to-change coding constructs. Case in point: The user specifies the number of points and the maximum y value for each point; named con- stants specify the window size and the window margin.





































































   623   624   625   626   627