1 Importjavax.swing.*;2 Importjava.awt.*;3 Importjava.awt.event.*;4 ImportJavax.swing.border.*;5 6 Public classLoancalculatorextendsJFrame {7 Private classButtonlistenerImplementsActionListener {8 @Override9 Public voidactionperformed (ActionEvent e) {Ten //TODO auto-generated Method Stub One Doubleinterest= A double.parsedouble (Jtfannualinterestrate.gettext ()); - intYear= - Integer.parseint (Jtfnumberofyears.gettext ()); the DoubleLoanamount= - double.parsedouble (Jtfloanamount.gettext ()); - - Doublemonthlyinterest=interest/1200; + DoubleMonthlypayment= loanamount*monthlyinterest/(1-1/math.pow (1 +Monthlyinterest, -Year*12)); + DoubleTotalpayment=monthlypayment*year*12; A atJtfmonthlypayment.settext (String.Format ("%.2f", Monthlypayment)); -Jtftotalpayment.settext (String.Format ("%.2f", Totalpayment)); - } - } - - PrivateJTextField jtfannualinterestrate=NewJTextField (); in PrivateJTextField jtfnumberofyears=NewJTextField (); - PrivateJTextField jtfloanamount=NewJTextField (); to PrivateJTextField jtfmonthlypayment=NewJTextField (); + PrivateJTextField jtftotalpayment=NewJTextField (); - the PrivateJButton jbtcomputeloan=NewJButton ("Compute Payment"); * $ PublicLoancalculator () {Panax NotoginsengJPanel p1=NewJPanel (NewGridLayout (5,2)); -P1.add (NewJLabel ("Annual Interest rate")); the P1.add (jtfannualinterestrate); +P1.add (NewJLabel ("Number of years")); A P1.add (jtfnumberofyears); theP1.add (NewJLabel ("Loan Amount")); + P1.add (jtfloanamount); -P1.add (NewJLabel ("Monthly Payment")); $ P1.add (jtfmonthlypayment); $P1.add (NewJLabel ("Total Payment")); - P1.add (jtftotalpayment); -P1.setborder (NewTitledborder ("Enter loan amount, interest rate," the+ "and Year")); - WuyiJPanel p2=NewJPanel (NewFlowLayout (flowlayout.right)); the P2.add (Jbtcomputeloan); - Add (p1,borderlayout.center); Wu Add (p2,borderlayout.south); -Jbtcomputeloan.addactionlistener (NewButtonlistener ()); About $ } - - Public Static voidMain (string[] args) { - //TODO auto-generated Method Stub ALoancalculator frame=Newloancalculator (); +Frame.settitle ("Loancalculator"); the Frame.pack (); -Frame.setlocationrelativeto (NULL); $ frame.setdefaultcloseoperation (jframe.exit_on_close); theFrame.setvisible (true); the } the the}
Java Design a loan calculator easy