Improve the BarChart class of Exercise P7.20 to work correctly when the data contains negative values.

Here is a sample program output:

.

Complete the following file:

BarChart.java

Use the following files:

BarChartComponent.java

import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
   The component class that displays the bar chart with negative values.
 */
public class BarChartComponent extends JComponent
{
   public void paintComponent(Graphics g)
   {  
      Graphics2D g2 = (Graphics2D) g;
      BarChart c = new BarChart(getWidth(), getHeight());
      c.add(1.1);
      c.add(-3.6);
      c.add(4.0);
      c.add(3.7);
      c.add(-2.1);
      c.add(.7);
      c.add(2.6);
      c.draw(g2);      
   }
}

ChartViewer.java

import javax.swing.*;

/**
   Displays a bar chart, with negative values.
*/
public class ChartViewer
{  
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();

      final int FRAME_WIDTH = 300;
      final int FRAME_HEIGHT = 400;

      frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
      frame.setTitle("ChartViewer");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      BarChartComponent component = new BarChartComponent();
      frame.add(component);

      frame.setVisible(true);
   }
}