calling a button's events
Hi guys. I'm making a mortgage calculator for my java class. the program calculates a monthly mortgage payment using the user-defined parameters, and when/if the user clicks the "Amortization table" button the program creates a Jtable and populates it with the loan details.
The problem I am having is that if the user clicks the "Amortization table" button without first clicking the "calculate" button, the program just creates a blank JTable.
What I want to do is: when the user clicks the "Amortization button", if the label in which the monthly payment goes is empty, then do all the events from the calculate button, then create the amortization table.
Is there a way for me to call button's events? or somehow activate another button?
[770 byte] By [
oc084a] at [2007-11-27 1:55:25]

make a method "makeCalculations()" that you will call when the "calculate" button is calledyou can then call this "makeCalculations()" method whenever you want, from anywhere in your class, including the actionPerformed(ActionEvent e) of the "Amortization button"
I tried that. The problem I was having was passing the user-entered amounts to the method. This is my current getPayment method
double getPayment(double dAmount, double dRate, int iTerm)
{
dPayment = (dAmount*(dRate/1200))/(1-Math.pow(1/(1+dRate/1200),(iTerm*12)));
return dPayment;
}
and this is my current actionPeformed for the calculate button:
public void actionPerformed(ActionEvent onClick)
{
Object src = onClick.getSource();
try
{
if(src == bCalc)
{
dAmount = Double.valueOf(tAmount.getText());
dRate = Double.valueOf(tRate.getText());
iTerm = Integer.parseInt(tTerm.getText());
lPaymentAmt.setText(""+(currency.format(getPayment(dAmount, dRate, iTerm))));
}
}
catch(Exception error)
{
JOptionPane.showMessageDialog(null, "Invalid Input. Please Try Again.","Input Error",
JOptionPane.ERROR_MESSAGE);
}
}
If i was to do this the way you suggested, how would I send the items from the textfields to the method. I tried using the getText() method but it wouldn't work.
Any ideas?
> can anybody help me?
My idea would be to start here:
"I tried using the getText() method but it wouldn't work."
Find out what "wouldn't work" means, what are the symptoms of "not working". Go from there. If that involves providing us with actual useful information, you could just do that.
Well, when the user clicks "calculate" set a variable calc=true(that means the user clicked the "calculate" button).
Then, inside the actions of "Amortization button" you check if the variable calc is equal true of false. When it磗 false, you just call the methods from "calculate" before performing the actions of "Amortization button".