将变量传递给Action事件

时间:2015-05-07 13:18:10

标签: java user-interface variables parameter-passing

我希望从3个ActionPerformed方法传递变量,或者找到除传递之外的替代方法,到我的jButtonActionPerformed方法。试图找出这个范围问题。

以下是一个actionperformed方法的示例,例如我想通过付款:

private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {                                            
    // TODO add your handling code here:
    monthlyPayment = jTextField4.getText();
    payment = Float.parseFloat(monthlyPayment);
}                                       

这是我需要付款的方法:

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:

    int months = 0;
    while (owed > 0){

        //for loop simulates a year
        for(int i=0; i<=11; i++){
            //break from loop if paid off!
            if (owed == 0){
                break;
            }
            owed -= payment;
            //counter for months
            months ++;
             }

        //adding interest
        owed*=rate;
    }

    String monthTotal = Integer.toString(months);
    jTextField5.setText(monthTotal);
}                                        

0 个答案:

没有答案