Hello I'm trying to create an application that will calculate an area based on width and height that a user enters and then use the area to calculate a cost based on a fixed rate. I get past compile errors but when I enter a height and weight it doesn't calculate and show an area. I tried to set a break point and debug but don't get anything useful with that. If someone could help me with this I would be greatful. Here is my code:
/**
*Calculates and displays commercial door estimate.
*
* @author (Shawn Newton)
* @version (10/2/2012)
*/
import java.awt.Image;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.NumberFormat;
public class CalculatorPanel extends JPanel
{
double aRate = 20.00;
double hRate = 15.00;
private JButton push;
private NumberFormat fmt;
private JLabel heightLabel, widthLabel, areaLabel, costLabel;
private JTextField height, width, area, cost;
public CalculatorPanel()
{
heightLabel = new JLabel ("Height: \n\t");
widthLabel = new
JLabel ( "Width: \n\t");
areaLabel = new
JLabel ( "Area: \n\t");
costLabel = new
JLabel ( "Cost: \n\t");
ButtonListener listener = new ButtonListener();
fmt = NumberFormat.getCurrencyInstance();
height = new JTextField (5);
width = new
JTextField (5);
area = new JTextField (5);
cost = new JTextField (5);
//cost = new JTextField (5);
push = new JButton("Calculate");
push.addActionListener( new
ButtonListener());
// cost.addActionListener ( new PaymentListener());
//num.addActionListener ( new PaymentListener());
//rate.addActionListener ( new PaymentListener());
add ( push );
add (heightLabel);
add (height);
add (widthLabel);
add (width);
add (areaLabel);
add (area);
add (costLabel);
add (cost);
setPreferredSize ( new
Dimension( 500, 250 ));
setBackground ( Color.cyan );
}
private class ButtonListener implements ActionListener
{
//
// Updates the monthly payment when the button is pushed.
//
public void actionPerformed (ActionEvent event)
{
double area = Integer.parseInt(height.toString()) * Integer.parseInt(width.toString());
}
}
public static void main ()
{
JFrame frame = new JFrame ("Door Cost Estimation");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
CalculatorPanel panel = new CalculatorPanel();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
public static void main (String[] args)
{
JFrame frame = new JFrame ( "CalculatorPanel");
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE);
CalculatorPanel panel = new CalculatorPanel ();
frame.getContentPane().add( panel );
frame.pack();
frame.setVisible( true );
}
}
//Math.pow(base, exponent) /// 2^3
// public String toString()
//
// {
//
// NumberFormat fmt = NumberFormat.getCurrencyInstance();
//
// return fmt.format(monthPayLabel);
//
// }