sclass JAmplitudeGraph extends JComponent { float[] values; public void paint(Graphics g) { int w = getWidth(), h = getHeight(); fillRect(g, 0, 0, w, h, getBackground()); float[] values = this.values; if (empty(values)) ret; Color fg = getForeground(); double factor = doubleRatio(l(values), w); for x to w: { int i1 = min(l(values)-1, ifloor(x*factor)); int i2 = max(i1+1, ifloor((x+1)*factor)); float val = 0; for (int i = i1; i < i2; i++) val = max(val, values[i]); int y = iround(val*h); fillRect(g, x, h-y, 1, y, fg); } } void setValues(float[] values) { this.values = values; repaint(); } }