Java Reference
In-Depth Information
/** Create the panel with the histogram. **/
public StreamedHistPanel (Histogram histogram) {
super (histogram);
fHistStream = new HistogramOutputStream ();
}
public OutputStream getOutputStream () {
return fHistStream;
}
/** This inner class provides the stream to write
* data.**/
class HistogramOutputStream extends OutputStream {
/** In OutputStream write (int b), only the lower byte
*ofthe int value is used but here we use the full
* value. **/
public synchronized void write (int data) {
// Convert back to double and shift down two
// decimal places.
histogram.add (((double)data)/100.0);
fNewDataFlag = true;
}
} // class HistogramOutputStream
} // class StreamedHistPanel
Such panels for each histogram can be added to the program display. The Web
Course Chapter 9: Te ch section includes the demonstration program Hist-
Stream.java ,which creates three instances of the StreamedHistPanel
and obtains the output stream for each, as shown in this snippet:
...GUI building in HistStreamApplet ...
for (int i = 0; i < NUM - HISTS; i++) {
histogram[i] = new Histogram ( " Sensor " +i,
" Data " , 25,0.0,10.0);
histPanel[i] = new StreamedHistPanel (histogram[i]);
// Add the histogram panels to the container panel
histsPanel.add (histPanel[i]);
// Get the output streams for each panel.
dataOut[i] = histPanel[i].getOutputStream ();
}
...
Search WWH ::




Custom Search