Java Reference
In-Depth Information
HistFormat , and HistPanel classes, illustrating the modularity of work-
ing with classes. Here the program adds the histogram panel HistPanel to its
content pane and also a panel with three buttons and a text field. The text field
displays the number of values to be generated for the histogram when the “Go”
button is pushed. The user can change this value. The “Clear” button empties the
histogram.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/** A demonstration of the Histogram class. **/
public class UIDrawHistApplet extends JApplet
implements ActionListener
{
// Use the HistPanel JPanel subclass here
HistPanel fOutputPanel;
Histogram fHistogram;
int fNumDataPoints = 100;
// A text field for input strings
JTextField fTextField;
// Flag for whether the applet is in a browser
// or running via the main () below.
boolean fInBrowser = true;
//Buttons
JButton fGoButton;
JButton fClearButton;
JButton fExitButton;
/**
*CreateaUserInterface with a text area with
*scrollbarsandaGobuttontoinitiate processing
*andaClearbutton to clear the textarea.
**/
public void init () {
Container content - pane = getContentPane ();
JPanel panel = new JPanel (new BorderLayout ());
// Create a histogram with Gaussian distribution.
makeHist ();
 
Search WWH ::




Custom Search