Java Reference
In-Depth Information
// JPanel subclass here.
fOutputPanel = new HistPanel (fHistogram);
panel.add (fOutputPanel,"Center");
// Use a textfield for an input parameter.
fTextField =
new JTextField (Integer.toString (fNumDataPoints), 10);
// If return hit after entering text, the
// actionPerformed will be invoked.
fTextField.addActionListener (this);
fGoButton = new JButton ("Go");
fGoButton.addActionListener (this);
fClearButton
=
new JButton (
"
Clear
"
);
fClearButton.addActionListener (this);
fExitButton
=
new JButton (
"
Exit
"
);
fExitButton.addActionListener (this);
JPanel control
-
panel
=
new JPanel ();
control
-
panel.add (fTextField);
control
-
panel.add (fGoButton);
control
-
panel.add (fClearButton);
control
-
panel.add (fExitButton);
if (fInBrowser) fExitButton.setEnabled (false);
panel.add (control
-
panel,
"
South
"
);
// Add text area with scrolling to the content pane.
content
-
pane.add (panel);
}
// init
/** Respond to buttons. **/
public void actionPerformed (ActionEvent e)
{
Object source
=
e.getSource ();
if (source
==
fGoButton
||
source
==
fTextField)
{
String strNumDataPoints
=
fTextField.getText ();
try {
fNumDataPoints = Integer.parseInt (strNumDataPoints);
} catch (NumberFormatException ex) {
// Could open an error dialog here but just
// display a message on the browser status line.
Search WWH ::
Custom Search