Java Reference
In-Depth Information
showStatus ("Bad input value");
return;
}
makeHist ();
repaint ();
} else if (source == fClearButton) {
fHistogram.clear ();
repaint ();
} else if (!fInBrowser)
System.exit (0);
} // actionPerformed
/** Create a histogram if it doesn't yet exit. Fill it
*withGaussian random distribution.
**/
void makeHist () {
// Create an instance of the Random class for
// producing our random values.
java.util.Random r = new java.util.Random ();
// The method nextGaussian in the class Random
// produces a value centered at 0.0 and a standard
// deviation of 1.0.
// Create an instance of our histogram class. Set the
// range so that it includes most of the distribution.
if (fHistogram == null)
fHistogram = new Histogram ( " Gaussian Distribution " ,
"random values",20,-3.0,3.0);
// Fill histogram with Gaussian distribution
for (int i = 0; i < fNumDataPoints; i++) {
double val = r.nextGaussian ();
fHistogram.add (val);
}
} // makeHist
/** Create a frame and add the applet to it. **/
public static void main (String[] args) {
// Dimensions for our frame
int frame - width = 450;
int frame - height = 300;
 
Search WWH ::




Custom Search