package chapter11; /** * Title: Chapter 11, "Creating User Interfaces" * Description: Examples for Chapter 11 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // Histogram.java: Display a histogram in a panel to show the // occurrence of the letters import javax.swing.*; import java.awt.*; public class Histogram extends JPanel { // Count the occurrence of 26 letters private int[] count; /**Set the count and display histogram*/ public void showHistogram(int[] count) { this.count = count; repaint(); } /**Paint the histogram*/ public void paintComponent(Graphics g) { if (count == null) return; // No display if count is null super.paintComponent(g); // Find the panel size and bar width and interval dynamically int width = getSize().width; int height = getSize().height; int interval = (width-40)/count.length; int individualWidth = (int)(((width-40)/24)*0.60); // Find the maximum count. The maximum count has the highest bar int maxCount = 0; for (int i=0; i