Page 700 - Introduction to Programming with Java: A Problem Solving Approach
P. 700
666 Chapter 16 GUI Programming Basics
//****************************************************
// Inner class for event handling.
private class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int x;
int xf;
try
{
// numeric value for user-entered x
// x factorial
}
// end class FactorialButton
{
}
// end actionPerformed
}
}
// end else
x = Integer.parseInt(xBox.getText());
catch (NumberFormatException nfe)
{
}
}
else
{
Apago PDF Enhancer
if (x == 0 || x == 1)
x = -1;
// indicates an invalid x
if (x < 0)
{
xfBox.setText("undefined");
{
}
else
{
}
// end else
xf = 1;
xf = 1;
for (int i=2; i<=x; i++)
{
}
xf *= i;
xfBox.setText(Integer.toString(xf));
} // end class Listener
//****************************************************
public static void main(String[] args)
new FactorialButton();
} // end main
Convert user-entered number from a string to a number.
Figure 16.8b FactorialButton program—part B