Java Mortgage Calculator Reading a Sequential File -


possible duplicate:
how populate jcombobox textfile?

ok, have issue here cannot quiet figure out. have file has variables on each line of: 5.35, 5.5, 5.75 in file called apr.txt. reading file , need populate file jcombobox. far have file being read fine cannot figure how populate jcombobox. must easy. can point me in proper direction?

thank in advance.

import java.awt.*; import java.text.numberformat; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.io.bufferedreader; import java.io.file; import java.io.filereader; import java.util.stringtokenizer;  import javax.swing.*; import javax.swing.jcombobox;      public class mortgagecalculatorgui9 extends jframe implements actionlistener         {          // declarations           //double [] interest = {5.35, 5.5, 5.75};          int [] length = {7, 15, 30};          double [] file_data = new double[3];            jlabel mortgagelabel = new jlabel( "principal amount:$ " );          jlabel paymentlabel = new jlabel( "monthly payment: " );          jlabel intratelabel = new jlabel( "interest rate %: " );          jlabel termlabel = new jlabel( "length of loan of loan in years: "  );          jtextfield mortgageprincipal = new jtextfield(7);          jtextfield payment = new jtextfield(7);          //jtextfield intratetext = new jtextfield(3);          jcombobox intratebox = new jcombobox();          jtextfield termtext = new jtextfield(3);          jbutton b7_535 = new jbutton( "7 years @ 5.35%" );          jbutton b15_55 = new jbutton( "15 years @ 5.50%" );          jbutton b30_575 = new jbutton( "30 years @ 5.75%");          jbutton exitbutton = new jbutton( "exit" );          jbutton clearbutton = new jbutton( "clear all" );          jbutton calculatebutton = new jbutton( "calculate loan" );          jtextarea loanpayments = new jtextarea(20,50);           jscrollpane scroll = new jscrollpane(loanpayments);          public mortgagecalculatorgui9()         {              //gui setup              super("mortgage calculator 1.0.5");              setsize(800, 400);              setlocation(500, 200);              setdefaultcloseoperation(jframe.exit_on_close);              jpanel pane = new jpanel(new gridlayout(3,1)); container grid = getcontentpane();              grid.setlayout(new gridlayout(4,0,4,4)); pane.add(grid);              pane.add(scroll);              grid.add(mortgagelabel);              grid.add(mortgageprincipal);              grid.add(intratelabel);              //grid.add(intratetext);              grid.add (intratebox);              grid.add(termlabel);              grid.add(termtext);              grid.add(paymentlabel);              grid.add(payment);              grid.add(b7_535);              grid.add(b15_55);              grid.add(b30_575);              grid.add(calculatebutton);              grid.add(clearbutton);              grid.add(exitbutton);              payment.seteditable(false);              setcontentpane(pane);              setcontentpane(pane);              setvisible(true);              //add gui functionality             calculatebutton.addactionlistener (this);             exitbutton.addactionlistener(this);             clearbutton.addactionlistener(this);             b7_535.addactionlistener(this);             b15_55.addactionlistener(this);             b30_575.addactionlistener(this);             mortgageprincipal.addactionlistener(this);             //intratetext.addactionlistener(this);             intratebox.addactionlistener (this);             termtext.addactionlistener(this);             payment.addactionlistener(this);           }              public void actionperformed(actionevent e)                  {                     object command = e.getsource();                      if (command == exitbutton)                  {                      system.exit(0);                   }                  else if (command == b7_535)                  {                      calcloan(length[0], file_data[0]);                   }                  else if (command == b15_55)                  {                      calcloan(length[1], file_data[1]);                   }                  else if (command == b30_575)                  {                      calcloan(length[2], file_data[2]);                   }                   else if (command == calculatebutton )                  {                      double terms = 0;                     double rates = 0;                     try                   {                      terms = double.parsedouble(termtext.gettext());                      //rates = double.parsedouble(intratetext.gettext());                      read_file ();                  }                     catch (exception ex)                  {                     loanpayments.settext("invalid term or rate amount");                     return;                  }                      calcloan(terms, rates);                   }                   else if (command == clearbutton)                  {                       mortgageprincipal.settext("");                      payment.settext("");                      //intratetext.settext("");                      termtext.settext("");                      loanpayments.settext("");                   }               }                //input file                  public void read_file()                 {                      file infile = new file("apr.txt");                      try                     {                          bufferedreader istream = new bufferedreader(new filereader(infile));                          for(int x=0;x<6;x++)                         {                             file_data[x]=double.parsedouble (istream.readline());                         }                        }                      catch (exception ex)                         {                              loanpayments.settext ("could not read file.");                             return;                          }                 }                    //this needs done                  private void calcloan(double terms, double rates)                   {                       termtext.settext(string.valueof(terms) );                      //intratetext.settext(string.valueof(rates));                      double amount = 0;                   try                  {                      amount = double.parsedouble(mortgageprincipal.gettext());                   }                      catch (exception ex)                   {                      loanpayments.settext("invalid mortgage amount");                     return;                   }                       double interestrate = rates;                       // calculations                      double intrate = (interestrate / 100) / 12;                      int months = (int)terms * 12;                      double rate = (intrate / 12);                      double payment = amount * intrate / (1 - (math.pow(1/(1 +  intrate), months)));                      double remainingprincipal = amount;                      double monthlyinterest = 0;                      double monthlyamt = 0;                      double[] balancearray = new double[months];                      double[] interestarray = new double[months];                      double[] montharray = new double[months];                      numberformat money =  numberformat.getcurrencyinstance();                      payment.settext(money.format(payment));                      loanpayments.settext("month\tprincipal\tinterest\tending  balance\n");                      int currentmonth = 0;                          while(currentmonth < months)                              {                               //create loop calculations                              monthlyinterest = (remainingprincipal * intrate);                              monthlyamt = (payment - monthlyinterest);                              remainingprincipal = (remainingprincipal - monthlyamt);                              loanpayments.append((++currentmonth) + "\t" + money.format(monthlyamt) + "\t" + money.format(monthlyinterest) + "\t" + money.format(remainingprincipal) + "\n");                              balancearray[currentmonth] = monthlyamt;                              interestarray[currentmonth] = monthlyinterest;                              montharray[currentmonth] = currentmonth;                               }                           }               public static void main(string[] args)              {               mortgagecalculatorgui9 frame= new mortgagecalculatorgui9();               }  } 

have looked @ jcombobox api suitable method? if start there, you'll right answer faster asking in stackoverflow (hint starts "add... , ends ...item") ;)


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -