Java Reference
In-Depth Information
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/** Demonstrate GUI building with multiple panels
* and event handling.
**/
public class
MultiPanelWithEvents
extends JApplet
implements ActionListener
{
InputsPanel fInputsPanel;
JTextArea fTextOutput;
/** Build the interface with InputsPanel
* and ActionButtonsPanel.
**/
public void init () {
Container content
-
pane = getContentPane ();
content
-
pane.setLayout (new GridLayout (1, 3));
// First create a panel of buttons
ActionButtonsPanel buttons
-
panel =
new ActionButtonsPanel (this);
. ..Rest same as in init() in MultiPanelApplet in
Chapter
6 ...
} // init
// Handle the button events. **/
public void actionPerformed (ActionEvent ae)
{
/** Get the values in the two text fields. **/
String str1
=
fInputsPanel.fTextfieldTop.getText ();
String str2
=
fInputsPanel.fTextfieldBot.getText ();
double val1=0.0;
double val2=0.0;
try {
val1 = Double.parseDouble (str1);
val2 = Double.parseDouble (str2);
} catch (NumberFormatException nfe) {
System.out.println ("Improper input");
}
Search WWH ::
Custom Search