Java Design a loan calculator easy

Source: Internet
Author: User
Tags gettext

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.