Make a bar chart to plot the following data set. Label each bar. Make the bars horizontal for easier labeling.

Bridge Name

Longest Span (ft)

Golden Gate

4,200

Brooklyn

1,595

Delaware Memorial

2,150

Mackinac

3,800

Provide a class BarChartViewer and a class BarChartComponent.

Here is a sample program output:

.

Complete the following files:

Bar.java

import java.awt.Rectangle; import java.awt.Graphics2D; /** This class describes a bar in a bar chart */ public class Bar { private int top; private int width; private String title; /** Constructs a bar. @param aTop the top of the bar @param aWidth the width of the bar @param aTitle the title for the bar */ public Bar(int aTop, int aWidth, String aTitle) { ... } /** Draws the bar. @param g2 the graphic context */ public void draw(Graphics2D g2) { ... } }

BarChartComponent.java

import javax.swing.JComponent; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Line2D; /** Draws a chart of bridge spans. */ public class BarChartComponent extends JComponent { public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // construct and draw four Bar objects } }

Use the following file:

BarChartViewer.java

import javax.swing.*;

public class BarChartViewer
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();

      frame.setSize(500, 400);
      frame.setTitle("BarChartViewer");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

      frame.setVisible(true);
   }
}