我正在尝试使用GUI进行抵押贷款计算器,我想在按下“计算”按钮后在第二个窗口输出功能calcAnnuity的结果。怎么做? 这是我的GUI图像:
功能,计算付款:
public void calcAnnuity(){
double totalMonths = (12 * years) + months;
double partOfRate = rate / 12.0 / 100.0;
double tempAmount = amount;
double payment = amount * partOfRate * Math.pow(1 + partOfRate, totalMonths) / (Math.pow(1 + partOfRate, totalMonths) - 1); //mathematical formula
DecimalFormat decFormat = new DecimalFormat("#.##");
System.out.println(1 + " Payment = " + decFormat.format(payment) + "--- Left to pay: " + decFormat.format(amount));
for(int i = 2; i <= totalMonths; i++) {
tempAmount -= (payment - partOfRate * amount);
amount -= payment;
System.out.println(i + " Payment = " + decFormat.format(payment) + " --- Left to pay: " + decFormat.format(tempAmount));
}
}
答案 0 :(得分:1)
在第二个窗口中,使用JLabel显示计算结果。单击“计算”按钮,使用setText()方法在JLabel中设置计算值。