Java Reference
In-Depth Information
private class
CalculateButtonHandler
implements
ActionListener
{
public void
actionPerformed(ActionEvent e)
{
double
width, length, area, perimeter;
length = Double.parseDouble(lengthTF.getText());
width = Double.parseDouble(widthTF.getText());
area = length * width;
perimeter = 2 * (length + width);
areaTF.setText("" + area);
perimeterTF.setText("" + perimeter);
}
}
private class
ExitButtonHandler
implements
ActionListener
{
public void
actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void
main(String[] args)
{
RectangleProgram rectObject =
new
RectangleProgram();
}
}
Sample Run: (Figure 6-8 shows the sample run.)
FIGURE 6-8
Sample run for the final
RectangleProgram
Search WWH ::
Custom Search