Why won’t this java work?
February 11th, 2010import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RectangleProgram extends JFrame
public final class Math
{
private JLabel lengthL, widthL,
areaL, perimeterL, diagonalL;
private JTextField lengthTF, widthTF,areaTF, perimeterTF, diagonalTF;
private JButton calculateB, exitB;
private CalculateButtonHandler cbHandler;
private ExitButtonHandler ebHandler;
private static final int WIDTH = 400;
private static final int HEIGHT = 600;
public RectangleProgram()
{
// Create four labels
lengthL = new JLabel(”Enter the length: “,
SwingConstants.RIGHT);
widthL = new JLabel(”Enter the width: “,
SwingConstants.RIGHT);
areaL = new JLabel(”Area: “,SwingConstants.RIGHT);
perimeterL = new JLabel(”Perimeter: “,
SwingConstants.RIGHT);
diagonalL = new JLabel(”Diagonal: “,
SwingConstants.RIGHT);
//Create four textfields
lengthTF = new JTextField(10);
widthTF = new JTextField(10);
areaTF = new JTextField(10);
perimeterTF = new JTextField(10);
diagonalTF = new JTextField(10);
//create Calculate Button
calculateB = new JButton(”Calculate”);
cbHandler = new CalculateButtonHandler();
calculateB.addActionListener(cbHandler);
//Create Exit Button
exitB = new JButton(”Exit”);
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
//Set the title of the window
setTitle(”Area and Perimeter of a Rectangle”);
//Get the container
Container pane = getContentPane();
//Set the layout
pane.setLayout(new GridLayout(6,2));
//Place all items created
pane.add(lengthL);
pane.add(lengthTF);
pane.add(widthL);
pane.add(widthTF);
pane.add(areaL);
pane.add(areaTF);
pane.add(perimeterL);
pane.add(perimeterTF);
pane.add(diagonalL);
pane.add(diagonalTF);
pane.add(calculateB);
pane.add(exitB);
//set the size of the window and display it
setSize(WIDTH,HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class CalculateButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double width, length, area, perimeter, diagonal;
length = Double.parseDouble(lengthTF.getText());
width = Double.parseDouble(widthTF.getText());
area = length * width;
perimeter = 2 * (length + width);
diagonal = ([width * width + length * length]* sqrt);
areaTF.setText(”" + area);
perimeterTF.setText(”" + perimeter);
diagonalTF.setText (”" + diagonal);
}
}
private class ExitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String[] args)
{
RectangleProgram rectObject = new RectangleProgram();
}
}
Earlene









