public void paintComponent (Graphics g)
    {
        super.paintComponent (g);

        // Background.
        Dimension D = this.getSize ();
        g.setColor (Color.white);
        g.fillRect (0,0, D.width, D.height);
        g.setColor (Color.black);


        // Axes, bounding box.
        g.drawLine (inset,D.height-inset, D.width-inset, D.height-inset);
        g.drawLine (inset,inset, inset,D.height-inset);
        g.drawLine (D.width-inset,inset, D.width-inset,D.height-inset);
        g.drawLine (inset,inset, D.width-inset, inset);

        // X-ticks and labels.
        int modVal = numIntervals / 5;
        for (int i=1; i<=numIntervals; i++) {
            double xTickd = i*delta;
            int xTick = (int) ( xTickd/(right-left) * (D.width-2*inset));
            g.drawLine (inset+xTick,D.height-inset-5, inset+xTick,D.height-inset+5);
            double x = left + i*delta;
            if (numIntervals <= 10) {
                g.drawString (df.format(x), xTick+inset-5, D.height-inset+20);
            }
            else if (i % modVal == 0) {
                // If there are too many values, write out only 5.
                g.drawString (df.format(x), xTick+inset-5, D.height-inset+20);
            }
            
        }

        // Y-ticks
        // First, find max.
        double maxY = Double.MIN_VALUE;
        for (int i=0; i<numIntervals; i++) {
            if (heights[i] > maxY) {
                maxY = heights[i];
            }
        }
        // We'll make only 10 ticks.
        int numYTicks = 10;
        double yDelta = maxY / numYTicks;
        for (int i=0; i<numYTicks; i++) {
            int yTick = (i+1) * (int) ((D.height-2*inset) / (double)numYTicks);
            g.drawLine (inset-5, D.height-yTick-inset, inset+5, D.height-yTick-inset);
            double yValue = (i+1)  * yDelta;
            g.drawString (df.format(yValue), 1, D.height-yTick-inset);
        }

        // Finally, draw the histogram.
        g.setColor (Color.blue);
        for (int i=0; i<numIntervals; i++) {
            int topLeftY = (int) ((heights[i] / maxY) * (D.height-2.0*inset));
            double x1 = i*delta;
            int topLeftX = (int) ( x1/(right-left) * (D.width-2*inset));
            double x2 = (i+1)*delta;
            int endX = (int) ( x2/(right-left) * (D.width-2*inset));
            int barWidth = endX - topLeftX - 10;
            g.fillRect (inset+topLeftX+5, D.height-topLeftY-inset, barWidth + 5, topLeftY + 5);
        }
        
    }