public class BarSortDisplay implements SortDisplay
1: import java.awt.*;
2:
3: public class BarSortDisplay implements SortDisplay {
4: public int getArraySize(Dimension d) {
5: return d.width / 3;
6: }
7: public void display(int a[], Graphics g, Dimension d) {
8: g.setColor(Color.white);
9: g.fillRect(0, 0, d.width, d.height);
10: double f = d.height / (double) a.length;
11: double cf = 255.0 / (double) a.length;
12: int x = d.width - 3;
13: for (int i = a.length; --i >= 0; x -= 3) {
14: g.setColor(new Color((int)(a[i] * cf / 1.5), (int)(a[i] * cf), 0));
15: g.fillRect(x, d.height - (int)(a[i] * f), 3, (int)(a[i] * f));
16: }
17: }
18: }