ICS3U Graphic Applications: Charting

The purpose of this investigation is to get you started in the direction of writing graphic applications in Java.

Task 1.

  1. Create the project ChartOps and a driver by the same name modeled after the example on page 59 of our textbook. Declare two static class variables width and height and set the frame dimensions to width×height = 500×500. Set an appropriate frame title.
  2. Create the class VerticalBarChart modeled after the RectangleComponent class described on page 61 of our textbook.
  3. After reviewing the RectangleViewer class on page 62, define a static class variable VerticalBarChart vbc add the necessary statements to ChartOps to view the two rectangles.

Task 2.

  1. Add the Searching project to the Build Path of ChartOps so we can exploit the use of the ArrayUtil class.
  2. Define the static class variable int[] data and instantiate an array of 50 ints in the main method of ChartOps driver ranging between 0 and height-50.
  3. Modify the VerticalBarChart constructor to receive and record data as its only parameter.
  4. Modify VerticalBarChart's the paintComponent method to display the array as a vertical bar chart.
  5. Correct the display of the rectangles to compensate for the origin being at the top left of the frame.

Task 3.

  1. Add a sort() method to ChartOps to order the elements of the data array.
  2. Add the method public void setData(int[] data) to VerticalBarChart to enable users to update its encapsulated array.
  3. Request the array be redrawn by calling vbc's repaint() method.
  4. A delay can be initiated by adding the code below. Embed this code within your sort() method to enable you to view the swapping activity.
      	try {
    		Thread.sleep(1000); 
    	} catch (InterruptedException e) {
    		e.printStackTrace();
    	}