Page 706 - Introduction to Programming with Java: A Problem Solving Approach
P. 706

                672 Chapter 16 GUI Programming Basics
 private class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
// end actionPerformed
int x;
// numeric value for user entered x
 int xf; // x factorial
if (e.getSource() == xBox)
This is the input text box.
  {
}
}
// end else button was clicked
JOptionPane.showMessageDialog(null,
"Click factorial button to perform calculation.");
else // the button must have been clicked
{
try
{
}
{
}
x = Integer.parseInt(xBox.getText());
catch (NumberFormatException nfe)
x = -1;
// indicates an invalid x
Apago PDF Enhancer
if (x < 0)
{
}
else
{
}
// end else
xfBox.setText("undefined");
if (x == 0 || x == 1)
{
}
else
{
}
// end else
xf = 1;
xf = 1;
for (int i=2; i<=x; i++)
{
}
xf *= i;
xfBox.setText(Integer.toString(xf));
} // end class Listener
Figure 16.12 Modified Listener class for the FactorialButton program













































   704   705   706   707   708