I'm working on a mortgage calculator program for school. I cannot get the Event to work properly and exhausted myself trying to figure out what I'm doing wrong - which is probably something really stupid - cause I'm feeling really stupid right now. My code is below - can someone give me an idea of what (probably everything) I'm doing wrong. I was referred to a program in "Sams, Teach Yourself Java 2 in 24 hours that is pulling a Thread - I don't think I need a thread but now don't know how to get rid of it. My double.parseDouble is not working either. Any help would be appreciated.
The code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MortgageEvent extends JFrame implements ActionListener {
Pattys_Mortgage gui;
Thread calculating;
public MortgageEvent(Pattys_Mortgage in) {
gui = in;
}
void startCalculating() {
calculating = new Thread(this);
calculating.start();
gui.calculate.setEnabled(false);
gui.quit.setEnabled(true);
gui.reset.setEnabled(false);
}
void stopCalculating() {
gui.quit.setEnabled(false);
gui.calculate.setEnabled(true);
gui.reset.setEnabled(true);
calculating = null;
}
void clearAllFields() {
gui.mortgage.setText(null);
gui.term.setText(null);
gui.interest.setText(null);
}
public void actionPerformed(ActionEvent calculate) {
String command = calculate.getActionCommand();
if(command == "Calculate")
startCalculating();
if(command == "Quit")
stopCalculating();
if(command == "Reset")
clearAllFields();
//declare variables
double amount = Double.parseDouble(mortgage.getText());
double term = Double.parseDouble(term.getText());
double rate = Double.parseDouble(rate.getText());
double results = Double.parseDouble(results.getText());
double noOfPayments = Double.parseDouble(noOfPayments());
}
public static double results(double amount, double noOfPayments,
double rate) {
double payment = ((amount*rate)/12/
(1-(Math.pow((1+(rate/12)),(-1*noOfPayments)))));
return payment;
//double.parseDouble(results.getText());
}
static public double parseDouble(results.getText())
{
return doubleValueOf(results);
}
}