Page 624 - Introduction to Programming with Java: A Problem Solving Approach
P. 624
590 Chapter 14 Exception Handling
/***************************************************************
*
LinePlotPanel.java
Dean & Dean
This class displays a line as a sequence of connected points.
***************************************************************/
*
*
*
import javax.swing.*; // for JPanel
import java.awt.*;
// for Graphics
public class LinePlotPanel extends JPanel
{
private int[] xPixels; // holds
x value for each plotted point
y value for each plotted point
rectangle with these specs:
private int[] yPixels; // holds
// Line plot is surrounded by a
private int topLeftX, topLeftY;
private int rectWidth, rectHeight;
//************************************************************
// Calculate dimensions for the line-plot rectangle, using the
// passed-in frame, which contains the frame's dimensions and
// coordinate
valuAesp. aFiglloin PxPDiFxelsEandhyaPinxeclsearrrays.
public LinePlotPanel(LinePlotGUI frame)
{
int numOfPoints = frame.getYCoords().length;
int pixelInterval;
// distance between adjacent points
topLeftX = topLeftY = frame.getMargin();
// getInsets works only
frame.setVisible(true);
rectWidth =
frame.getWidth() - (2
if setVisible is called first
* topLeftX +
frame.getInsets().left + frame.getInsets().right);
rectHeight =
frame.getHeight() - (2 * topLeftY +
frame.getInsets().top + frame.getInsets().bottom);
Figure 14.21a
LinePlotPanel class—part A
window-resizing slowdown might be noticeable. Slow is acceptable for some things, like initially loading a program, but not for graphical user interface things, like resizing a window. Users are an impatient bunch. Have you ever thumped your mouse in a fit of haste?