Page 752 - Introduction to Programming with Java: A Problem Solving Approach
P. 752
718 Chapter 17 GUI Programming—Component Layout, Additional GUI Components
}
// end class MathCalculator
}
// end actionPerformed
try
{
}
}
// end if
}
// end else
x = Double.parseDouble(xBox.getText());
catch (NumberFormatException nfe)
{
}
x = -1;
// indicates an invalid x
if (e.getActionCommand().equals("sqrt x"))
{
if (x < 0)
{
}
else
{
}
xSqrtBox.setText("undefined");
result = Math.sqrt(x);
xSqrtBox.setText(String.format("%7.5f", result));
else // calculate logarithm
{
Apago PDF Enhancer
if (x < 0)
{
}
else
{
}
xLogBox.setText("undefined");
result = Math.log10(x);
xLogBox.setText(String.format("%7.5f", result));
} // end class Listener
//**********************************************************
public static void main(String[] args)
{
new MathCalculator();
} // end main
Figure 17.9c MathCalculator program—part C