Java Reference
In-Depth Information
public void write (int b)
{
double val
=
((double)b)/100.0;
int ival =
(int) (100.0 * ((val - fPedestal)/fSlope));
try {
out.write (ival);
}
catch (IOException ioe) {}
} // write
// Not overrriding other methods in FilterOutputStream.
} // class HistFilterOutputStream
The applet
HistFilterStream
in the Web Course Chapter 9:
Te ch
section
displays data from three sensors (artificially generated data) in instances of the
StreamHistPanel
class discussed in the previous section. The data for each
sensor is generated with a different slope and pedestal to simulate real world
variations in measurement data. By wrapping the streams going into the histogram
with
HistFilterOutputStream
,wecan calibrate the data before it reaches
the histogram.
The applet displays a row of
StreamHistPanel
histograms with raw data
and a row below this one showing histograms with the calibrated data. In the
interface building section of the program, the code snippet here shows the
section that creates the top row of histogram panels and then the bottom row
(
NUM
-
HISTS
=
3
):
...GUI building in
HistFilterStreamApplet
...
for (int i=0; i < NUM
-
HISTS; i++) {
fHistogram[i] = new Histogram ("Sensor " +i,
"Data", 25,0.0,10.0);
fHistPanel[i] = new StreamedHistPanel (fHistogram[i]);
// Add the histogram panels to the container panel
fHistsPanel.add (fHistPanel[i]);
// Get the output streams for each panel.
fDataOut[i]
=
fHistPanel[i].getOutputStream ();
}
// Create HistPanels for the calibrated sensor
// histograms.
for (int i=0; i < NUM
-
HISTS; i++) {
Search WWH ::
Custom Search