Galaxylokka
Galaxylokka

Reputation: 67

EventDispatchThread Execption

I create alist method to insert principal values and remaining balances according to the payments.But when I implement this method in actionListner method error occurs(EventDispatchThread Execption).I try to solve it.Please give any help for me to solve this.

public class Loan {
    float lamt,irate,inst,lbalance;
    int duration,nop;
    String amtlist[][] = new String[duration+1][5];

    Loan(float lamt, float irate, int duration, int nop) {
        this.lamt = lamt;
        this.irate = irate;
        this.duration = duration;
        this.nop = nop;
    }

    public void alist() {
        amtlist[0][0] = "0" ;
        amtlist[0][1] = "0";
        amtlist[0][2] = "0";
        amtlist[0][3] = "0";
        amtlist[0][4] = Float.toString(inst*annuity(duration,irate));

        float v = 1 / (1 + irate);
        for (int i = 1; i < duration + 1; i++) {
            amtlist[i][0] = Float.toString(i);
            amtlist[i][1] = Float.toString(irate * annuity(duration + 1 - i, irate));
            amtlist[i][2] = Float.toString(instalment());
            amtlist[i][3] = Double.toString(instalment() * Math.pow(v, i));
            amtlist[i][4] = Float.toString(instalment() * annuity(duration - i, irate));
        }
    }

    public float annuity(int duration, float irate) {
        float v = 1 / (1 + irate);
        float an = (float) ((1 - Math.pow(v, duration)) / irate);
        return an;
    }

    public float instalment(){
        return inst = lamt / annuity(duration, irate);
    }

    public float lbalance() {
        return lbalance = inst * annuity(duration - nop, irate);
    }
}

public void actionPerformed(ActionEvent e) {
    String lamtstr = tf1.getText();
    String iratestr = tf2.getText();
    String durationstr = tf3.getText();
    String nopstr = tf4.getText();

    float lamt = Float.parseFloat(lamtstr);
    float irate = Float.parseFloat(iratestr);
    int duration = Integer.parseInt(durationstr);
    int nop = Integer.parseInt(nopstr);

    Loan l = new Loan(lamt, irate, duration, nop);
    float inst = 0, balance = 0;
    if (e.getSource() == b1) {
        inst =l.instalment();
        balance =l.lbalance();
    }
    if (e.getSource() == b2) {
        l.alist();
        fscr.dispose();
        new AmTable(l.amtlist);
    }
    tf5.setText(String.valueOf(inst));
    tf6.setText(String.valueOf(balance));
}

I tried solve it by changing alist method to value returning method but my attempt got vain.

if (e.getSource() == b2) {
    l.alist();
    fscr.dispose();
    new AmTable(l.amtlist);
}

I expected to call AmTable function with amlist array.

Upvotes: 0

Views: 32

Answers (0)

Related Questions