Results 1 to 15 of 15
  1. #1
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default Help with GUIs in Netbeans!

    Hi, I need help with a GUI. I am trying to understand it. I am not getting the program to do the calculations when I press the button calculate. I know I am to enter the methods under the ActionPerformed code in Netbeans. I am not sure where I am going wrong, and it is probably something simple. I know the method should include the input I get from each TextField of mortgage, interest rate, and loan term. Can you please try to explain this to me? If I already have the methods, how do I get it to sync with the calculate button and display in another textField. Thanks. My application runs, but it does not calculate and display. I have the clear button working.

    private void mortgagecalculatedTextField4ActionPerformed(java.a wt.event.ActionEvent evt) {
    double monPay = 0;
    System.out.println("" + Math.round(monPay)+ ".");
    //calculates the mortgage payment amount based on amount entered by user // TODO add your handling code here:
    }

    private void calculateButton7ActionPerformed(java.awt.event.Act ionEvent evt) {
    double monIntRate = 0.0;//initiates the monthly interest rate
    double monPay = 0;//initiates the mortgage payment

    double intsPaid = 0;//initiates interest paid
    double princPaid = 0;//initiates principal paid
    double intRates = 0;
    monIntRate = intRates/12;//interest rate divided by 12 months equals the monthly interest rate
    int loanTerm = 0;
    double totMons = loanTerm*12;//term of loan multiplied by 12 months equals total months of term
    double amLoanOne = 0;
    double amLoanNxt = amLoanOne;//initiates the amount of loan balance after initial amount

    monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
    //calculates the mortgage payment
    intsPaid = amLoanOne*monIntRate;
    //calculates the interest paid
    princPaid = monPay - intsPaid;
    //calculates the principal paid
    amLoanNxt = amLoanOne - princPaid;
    //calculates the amount of loan balance after initial amount // TODO add your handling code here:
    }

    private void clearjButton8ActionPerformed(java.awt.event.Action Event evt) {
    mortgageTextField1.setText("");
    loantermTextField2.setText("");
    interestrateTextField3.setText("");
    mortgagecalculatedTextField4.setText("");
    loancalculatedTextField5.setText("");
    interestcalculatedTextField6.setText("");




    // TODO add your handling code here:
    }

    private void mortgageTextField1ActionPerformed(java.awt.event.A ctionEvent evt) {
    Scanner scan = new Scanner(System.in);
    double amLoanOne = scan.nextDouble(); // TODO add your handling code here:
    }

    private void loantermTextField2ActionPerformed(java.awt.event.A ctionEvent evt) {
    Scanner scan = new Scanner(System.in);
    double loanTerm = scan.nextDouble(); // TODO add your handling code here:
    }

    private void interestrateTextField3ActionPerformed(java.awt.eve nt.ActionEvent evt) {
    Scanner scan = new Scanner(System.in);
    double intRates = scan.nextDouble(); // TODO add your handling code here:
    }

    private void loancalculatedTextField5ActionPerformed(java.awt.e vent.ActionEvent evt) {
    Scanner scan = new Scanner(System.in);
    double amLoanOne = scan.nextDouble();
    double amLoanNxt = amLoanOne;
    System.out.println("" + Math.round(amLoanNxt)+ ".");
    //calculates the loan balance based on the amount entered by user // TODO add your handling code here:
    }
    Java Code:
        private void interestcalculatedTextField6ActionPerformed(java.awt.event.ActionEvent evt) {                                                             
       Scanner scan = new Scanner(System.in);
       double intsPaid = 0; 
       double monIntRate = 0.0;
       double amLoanOne = scan.nextDouble();
       intsPaid = amLoanOne*monIntRate;
       
       double amLoanNxt = amLoanOne;
       System.out.println("" + Math.round(intsPaid)+ ".");
          //calculates the interest paid with interest rate of user input. ex. of .0575
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    I am not getting the program to do the calculations when I press the button calculate.
    What is happening when you press the button? Is there an error?

    I see that you are trying to use the Scanner class in the action listeners.
    If you are using GUI to get the input from the user, you shouldn't use Scanner. The user should type the input into the text fields and then press enter. The listener code should get the contents of the text fields, check for valid data and then do the calculation and put the results out in another GUI component.
    So take out ALL of the Scanners in the listeners.

  3. #3
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default RE::

    When I press the button, it does not show the values, or calculations.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Add a System.out.println() in the action listener code to be sure you are calling that method.
    Your posted code is too fragmented to be of any use for helping you with your logic.

    When you post code, Please put it all in code tags. You only put the last bit in code tags.

  5. #5
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    Hi. These are my methods and I am confused about how to get these to work with my calculate button and then display in the associated text fields of interest, loan, and mortgage amounts. Please help me to understand.
    Java Code:
        double monIntRate = 0.0;//initiates the monthly interest rate
        double monPay = 0;//initiates the mortgage payment 
        
        double intsPaid = 0;//initiates interest paid 
        double princPaid = 0;//initiates principal paid
        monIntRate = intRates/12;//interest rate divided by 12 months equals the monthly interest rate
        double totMons = loanTerm*12;//term of loan multiplied by 12 months equals total months of term
        double amLoanNxt = amLoanOne;//initiates the amount of loan balance after initial amount
        monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
        //calculates the mortgage payment
           intsPaid = amLoanOne*monIntRate; 
        //calculates the interest paid
           princPaid = monPay - intsPaid;
        //calculates the principal paid  
           amLoanNxt = amLoanOne - princPaid;
        //calculates the amount of loan balance after initial amount
    System.out.println("Interest amount is $" + Math.round(intsPaid)+ ".");
          //calculates the interest paid with interest rate entered by user
          System.out.println("Mortgage payment amount is $"  + Math.round(monPay)+ ".");
          //calculates the mortgage payment amount based on amount entered by user
          System.out.println("Loan balance amount is $" + Math.round(amLoanNxt)+  ".");
          //calculates the loan balance based on the amount entered by user

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    how to get these to work with my calculate button
    Is the action listener code called when you press the calculate button?
    Where is the results of the calculations supposed to be displayed?
    Does the listener code put any values into the display areas?

    For the code you just posted, it looks like a bunch of math that you will have to work our yourself to see if you have the correct formulas and expressions. You can fix that later after you get the code to execute correctly and put a value in the output area.

  7. #7
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default RE::

    Hi. The calculations are supposed to display in a separate text field. No values display in the text field areas.

  8. #8
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    Here is my GUI coding.
    Java Code:
    package mortgage;
    
    import java.util.Scanner;
    
    /**
     *package
     * @author Lekeisha
     */
    public class MortgageGUI extends javax.swing.JFrame {
        private Object display;
    
        /** Creates new form MortgageGUI */
        public MortgageGUI() {
            initComponents();
            
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jPanel1 = new javax.swing.JPanel();
            mortgageTextField1 = new javax.swing.JTextField();
            loantermTextField2 = new javax.swing.JTextField();
            interestrateTextField3 = new javax.swing.JTextField();
            mortgagecalculatedTextField4 = new javax.swing.JTextField();
            loancalculatedTextField5 = new javax.swing.JTextField();
            interestcalculatedTextField6 = new javax.swing.JTextField();
            mortgageLabel1 = new javax.swing.JLabel();
            loantermLabel3 = new javax.swing.JLabel();
            interestrateLabel5 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            calculateButton7 = new javax.swing.JButton();
            clearjButton8 = new javax.swing.JButton();
            jLabel9 = new javax.swing.JLabel();
            jLabel11 = new javax.swing.JLabel();
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Mortgage Calculator");
    
            mortgageTextField1.setText("200000");
            mortgageTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mortgageTextField1ActionPerformed(evt);
                }
            });
    
            loantermTextField2.setText("30");
            loantermTextField2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    loantermTextField2ActionPerformed(evt);
                }
            });
    
            interestrateTextField3.setText(".0575");
            interestrateTextField3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    interestrateTextField3ActionPerformed(evt);
                }
            });
    
            mortgagecalculatedTextField4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mortgagecalculatedTextField4ActionPerformed(evt);
                }
            });
    
            loancalculatedTextField5.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    loancalculatedTextField5ActionPerformed(evt);
                }
            });
    
            interestcalculatedTextField6.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    interestcalculatedTextField6ActionPerformed(evt);
                }
            });
    
            mortgageLabel1.setText("Mortgage Amount");
    
            loantermLabel3.setText("Loan Term");
    
            interestrateLabel5.setText("Interest Rate");
    
            jLabel7.setText("Mortgage Amount");
    
            calculateButton7.setText("Calculate");
            calculateButton7.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    calculateButton7ActionPerformed(evt);
                }
            });
    
            clearjButton8.setText("Clear");
            clearjButton8.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    clearjButton8ActionPerformed(evt);
                }
            });
    
            jLabel9.setText("Loan Balance");
    
            jLabel11.setText("Interest Amount");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(77, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(mortgageLabel1)
                        .addComponent(jLabel7)
                        .addComponent(mortgageTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mortgagecalculatedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(loantermLabel3)
                        .addComponent(loantermTextField2)
                        .addComponent(loancalculatedTextField5))
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(interestrateTextField3, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(interestrateLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(interestcalculatedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(239, 239, 239)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(calculateButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(clearjButton8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGap(108, 108, 108))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(loantermLabel3)
                                .addComponent(interestrateLabel5)
                                .addComponent(mortgageLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(loantermTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(interestrateTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(mortgageTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(20, 20, 20))
                        .addComponent(calculateButton7, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addGap(40, 40, 40)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(jLabel11)
                        .addComponent(jLabel7))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(loancalculatedTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(interestcalculatedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mortgagecalculatedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(clearjButton8)
                    .addContainerGap(101, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
     
        private void mortgagecalculatedTextField4ActionPerformed(java.awt.event.ActionEvent evt) {                                                             
           double monPay = 0;
           System.out.println(""  + Math.round(monPay)+ ".");
          //calculates the mortgage payment amount based on amount entered by user // TODO add your handling code here:
        }                                                            
    
        private void calculateButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                                 
     double monIntRate = 0.0;//initiates the monthly interest rate
        double monPay = 0;//initiates the mortgage payment 
        
        double intsPaid = 0;//initiates interest paid 
        double princPaid = 0;//initiates principal paid
        double intRates = 0;
        monIntRate = intRates/12;//interest rate divided by 12 months equals the monthly interest rate
        double loanTerm = 0;
        double totMons = loanTerm*12;//term of loan multiplied by 12 months equals total months of term
            double amLoanOne = 0;
        double amLoanNxt = amLoanOne;//initiates the amount of loan balance after initial amount
        
        monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
        //calculates the mortgage payment
           intsPaid = amLoanOne*monIntRate; 
        //calculates the interest paid
           princPaid = monPay - intsPaid;
        //calculates the principal paid  
           amLoanNxt = amLoanOne - princPaid;
        //calculates the amount of loan balance after initial amount       // TODO add your handling code here:
        }                                                
    
        private void clearjButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                              
          mortgageTextField1.setText("");
          loantermTextField2.setText("");
          interestrateTextField3.setText("");
          mortgagecalculatedTextField4.setText("");
          loancalculatedTextField5.setText("");
          interestcalculatedTextField6.setText("");
          
          
          
          
         // TODO add your handling code here:
        }                                             
    
        private void mortgageTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                                   
         Scanner scan = new Scanner(System.in);
         double amLoanOne = scan.nextDouble();  // TODO add your handling code here:
        }                                                  
    
        private void loantermTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        Scanner scan = new Scanner(System.in);
        double loanTerm = scan.nextDouble();    // TODO add your handling code here:
        }                                                  
    
        private void interestrateTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                                       
        Scanner scan = new Scanner(System.in);
        double intRates = scan.nextDouble();    // TODO add your handling code here:
        }                                                      
    
        private void loancalculatedTextField5ActionPerformed(java.awt.event.ActionEvent evt) {                                                         
       Scanner scan = new Scanner(System.in);
       double amLoanOne = scan.nextDouble();
       double amLoanNxt = amLoanOne;
               System.out.println("" + Math.round(amLoanNxt)+  ".");
          //calculates the loan balance based on the amount entered by user     // TODO add your handling code here:
        }                                                        
    
        private void interestcalculatedTextField6ActionPerformed(java.awt.event.ActionEvent evt) {                                                             
       Scanner scan = new Scanner(System.in);
       double intsPaid = 0; 
       double monIntRate = 0.0;
       double amLoanOne = scan.nextDouble();
       intsPaid = amLoanOne*monIntRate;
       
       double amLoanNxt = amLoanOne;
       System.out.println("" + Math.round(intsPaid)+ ".");
          //calculates the interest paid with interest rate entered by user     // TODO add your handling code here:
        }                                                            
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new MortgageGUI().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify                     
        private javax.swing.JButton calculateButton7;
        private javax.swing.JButton clearjButton8;
        private javax.swing.JTextField interestcalculatedTextField6;
        private javax.swing.JLabel interestrateLabel5;
        private javax.swing.JTextField interestrateTextField3;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JTextField loancalculatedTextField5;
        private javax.swing.JLabel loantermLabel3;
        private javax.swing.JTextField loantermTextField2;
        private javax.swing.JLabel mortgageLabel1;
        private javax.swing.JTextField mortgageTextField1;
        private javax.swing.JTextField mortgagecalculatedTextField4;
        // End of variables declaration                   
    }

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    You have not removed the use of the Scanner class as suggested in post#2.

    Your action listener for the calculate button does not put any results of the calculation into any text field.

  10. #10
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default RE::

    I will make adjustments and repost. Thanks.

  11. #11
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default RE::

    Here is the error code I got from running the application
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - inconvertible types
      required: double
      found:    java.lang.String
    	at mortgage.MortgageGUI.calculateButton7ActionPerformed(MortgageGUI.java:211)
    	at mortgage.MortgageGUI.access$600(MortgageGUI.java:19)
    	at mortgage.MortgageGUI$7.actionPerformed(MortgageGUI.java:117)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    	at java.awt.Component.processMouseEvent(Component.java:6288)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    	at java.awt.Component.processEvent(Component.java:6053)
    	at java.awt.Container.processEvent(Container.java:2041)
    	at java.awt.Component.dispatchEventImpl(Component.java:4651)
    	at java.awt.Container.dispatchEventImpl(Container.java:2099)
    	at java.awt.Component.dispatchEvent(Component.java:4481)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    	at java.awt.Container.dispatchEventImpl(Container.java:2085)
    	at java.awt.Window.dispatchEventImpl(Window.java:2478)
    	at java.awt.Component.dispatchEvent(Component.java:4481)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
    	at java.awt.EventQueue.access$000(EventQueue.java:84)
    	at java.awt.EventQueue$1.run(EventQueue.java:602)
    	at java.awt.EventQueue$1.run(EventQueue.java:600)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    	at java.awt.EventQueue$2.run(EventQueue.java:616)
    	at java.awt.EventQueue$2.run(EventQueue.java:614)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Here is my revised version of my application. I am confused about where I am going wrong. Please help. Thanks.
    Java Code:
    package mortgage;
    
    import java.util.Scanner;
    
    /**
     *
     * @author Lekeisha
     */
    public class MortgageGUI extends javax.swing.JFrame {
        
    
        /** Creates new form MortgageGUI */
        public MortgageGUI() {
            initComponents();
            
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jPanel1 = new javax.swing.JPanel();
            mortgageTextField1 = new javax.swing.JTextField();
            loantermTextField2 = new javax.swing.JTextField();
            interestrateTextField3 = new javax.swing.JTextField();
            mortgagecalculatedTextField4 = new javax.swing.JTextField();
            loancalculatedTextField5 = new javax.swing.JTextField();
            interestcalculatedTextField6 = new javax.swing.JTextField();
            mortgageLabel1 = new javax.swing.JLabel();
            loantermLabel3 = new javax.swing.JLabel();
            interestrateLabel5 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            calculateButton7 = new javax.swing.JButton();
            clearjButton8 = new javax.swing.JButton();
            jLabel9 = new javax.swing.JLabel();
            jLabel11 = new javax.swing.JLabel();
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Mortgage Calculator");
    
            mortgageTextField1.setText("200000");
            mortgageTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mortgageTextField1ActionPerformed(evt);
                }
            });
    
            loantermTextField2.setText("30");
            loantermTextField2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    loantermTextField2ActionPerformed(evt);
                }
            });
    
            interestrateTextField3.setText(".0575");
            interestrateTextField3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    interestrateTextField3ActionPerformed(evt);
                }
            });
    
            mortgagecalculatedTextField4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mortgagecalculatedTextField4ActionPerformed(evt);
                }
            });
    
            loancalculatedTextField5.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    loancalculatedTextField5ActionPerformed(evt);
                }
            });
    
            interestcalculatedTextField6.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    interestcalculatedTextField6ActionPerformed(evt);
                }
            });
    
            mortgageLabel1.setText("Mortgage Amount");
    
            loantermLabel3.setText("Loan Term");
    
            interestrateLabel5.setText("Interest Rate");
    
            jLabel7.setText("Mortgage Amount");
    
            calculateButton7.setText("Calculate");
            calculateButton7.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    calculateButton7ActionPerformed(evt);
                }
            });
    
            clearjButton8.setText("Clear");
            clearjButton8.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    clearjButton8ActionPerformed(evt);
                }
            });
    
            jLabel9.setText("Loan Balance");
    
            jLabel11.setText("Interest Amount");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(77, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(mortgageLabel1)
                        .addComponent(jLabel7)
                        .addComponent(mortgageTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mortgagecalculatedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(loantermLabel3)
                        .addComponent(loantermTextField2)
                        .addComponent(loancalculatedTextField5))
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(interestrateTextField3, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(interestrateLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(interestcalculatedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(239, 239, 239)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(calculateButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(clearjButton8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGap(108, 108, 108))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(loantermLabel3)
                                .addComponent(interestrateLabel5)
                                .addComponent(mortgageLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(loantermTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(interestrateTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(mortgageTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(20, 20, 20))
                        .addComponent(calculateButton7, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addGap(40, 40, 40)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(jLabel11)
                        .addComponent(jLabel7))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(loancalculatedTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(interestcalculatedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mortgagecalculatedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(clearjButton8)
                    .addContainerGap(101, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
     
        private void mortgagecalculatedTextField4ActionPerformed(java.awt.event.ActionEvent evt) {                                                             
           
          //calculates the mortgage payment amount based on amount entered by user // TODO add your handling code here:
        }                                                            
    
        private void calculateButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                                 
            double intRates = 0;
            //initiates the monthly interest rate
            //initiates the mortgage payment
            //initiates interest paid
            //initiates principal paid
            double monIntRate = intRates/12; //interest rate divided by 12 months equals the monthly interest rate
            double loanTerm = 0;
            double totMons = loanTerm*12; //term of loan multiplied by 12 months equals total months of term
            double amLoanOne = (double)(mortgageTextField1.getText());
            //initiates the amount of loan balance after initial amount
            double monPay = (double)(mortgageTextField1.getText())*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
          mortgagecalculatedTextField4.setText(monPay + "Mortgage Amount");
            //calculates the mortgage payment
            double intsPaid = (double)(mortgageTextField1.getText()*monIntRate);
            interestcalculatedTextField6.setText(intsPaid + "Interest Amount");
            //calculates the interest paid
            double princPaid = monPay - intsPaid;
            //calculates the principal paid
            double amLoanNxt = (double)(mortgageTextField1.getText()- princPaid);
            loancalculatedTextField5.setText(amLoanNxt + "Loan Amount");
            //calculates the amount of loan balance after initial amount  
           
           
           
        }                                                
    
        private void clearjButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                              
          mortgageTextField1.setText("");
          loantermTextField2.setText("");
          interestrateTextField3.setText("");
          mortgagecalculatedTextField4.setText("");
          loancalculatedTextField5.setText("");
          interestcalculatedTextField6.setText("");
          
          
          
          
         // TODO add your handling code here:
        }                                             
    
        private void mortgageTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                                   
            String amLoanOne = mortgageTextField1.getText(); // TODO add your handling code here:
        }                                                  
    
        private void loantermTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        String loanTerm = loantermTextField2.getText();    // TODO add your handling code here:
        }                                                  
    
        private void interestrateTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                                       
        String intRates = interestrateTextField3.getText();    // TODO add your handling code here:
        }                                                      
    
        private void loancalculatedTextField5ActionPerformed(java.awt.event.ActionEvent evt) {                                                         
       
               
          //calculates the loan balance based on the amount entered by user     // TODO add your handling code here:
        }                                                        
    
        private void interestcalculatedTextField6ActionPerformed(java.awt.event.ActionEvent evt) {                                                             
       Scanner scan = new Scanner(System.in);
       double intsPaid = 0; 
       double monIntRate = 0.0;
       double amLoanOne = scan.nextDouble();
       intsPaid = amLoanOne*monIntRate;
       
       double amLoanNxt = amLoanOne;
       System.out.println("" + Math.round(intsPaid)+ ".");
          //calculates the interest paid with interest rate entered by user     // TODO add your handling code here:
        }                                                            
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new MortgageGUI().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify                     
        private javax.swing.JButton calculateButton7;
        private javax.swing.JButton clearjButton8;
        private javax.swing.JTextField interestcalculatedTextField6;
        private javax.swing.JLabel interestrateLabel5;
        private javax.swing.JTextField interestrateTextField3;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JTextField loancalculatedTextField5;
        private javax.swing.JLabel loantermLabel3;
        private javax.swing.JTextField loantermTextField2;
        private javax.swing.JLabel mortgageLabel1;
        private javax.swing.JTextField mortgageTextField1;
        private javax.swing.JTextField mortgagecalculatedTextField4;
        // End of variables declaration                   
    }

  12. #12
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    Hi, I saw I left one with the Scanner method so I removed that. Here it is without all the Scanner methods. Thanks.
    Java Code:
    package mortgage;
    
    import java.util.Scanner;
    
    /**
     *
     * @author Lekeisha
     */
    public class MortgageGUI extends javax.swing.JFrame {
        
    
        /** Creates new form MortgageGUI */
        public MortgageGUI() {
            initComponents();
            
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jPanel1 = new javax.swing.JPanel();
            mortgageTextField1 = new javax.swing.JTextField();
            loantermTextField2 = new javax.swing.JTextField();
            interestrateTextField3 = new javax.swing.JTextField();
            mortgagecalculatedTextField4 = new javax.swing.JTextField();
            loancalculatedTextField5 = new javax.swing.JTextField();
            interestcalculatedTextField6 = new javax.swing.JTextField();
            mortgageLabel1 = new javax.swing.JLabel();
            loantermLabel3 = new javax.swing.JLabel();
            interestrateLabel5 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            calculateButton7 = new javax.swing.JButton();
            clearjButton8 = new javax.swing.JButton();
            jLabel9 = new javax.swing.JLabel();
            jLabel11 = new javax.swing.JLabel();
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Mortgage Calculator");
    
            mortgageTextField1.setText("200000");
            mortgageTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mortgageTextField1ActionPerformed(evt);
                }
            });
    
            loantermTextField2.setText("30");
            loantermTextField2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    loantermTextField2ActionPerformed(evt);
                }
            });
    
            interestrateTextField3.setText(".0575");
            interestrateTextField3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    interestrateTextField3ActionPerformed(evt);
                }
            });
    
            mortgagecalculatedTextField4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mortgagecalculatedTextField4ActionPerformed(evt);
                }
            });
    
            loancalculatedTextField5.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    loancalculatedTextField5ActionPerformed(evt);
                }
            });
    
            interestcalculatedTextField6.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    interestcalculatedTextField6ActionPerformed(evt);
                }
            });
    
            mortgageLabel1.setText("Mortgage Amount");
    
            loantermLabel3.setText("Loan Term");
    
            interestrateLabel5.setText("Interest Rate");
    
            jLabel7.setText("Mortgage Amount");
    
            calculateButton7.setText("Calculate");
            calculateButton7.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    calculateButton7ActionPerformed(evt);
                }
            });
    
            clearjButton8.setText("Clear");
            clearjButton8.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    clearjButton8ActionPerformed(evt);
                }
            });
    
            jLabel9.setText("Loan Balance");
    
            jLabel11.setText("Interest Amount");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(77, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(mortgageLabel1)
                        .addComponent(jLabel7)
                        .addComponent(mortgageTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mortgagecalculatedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(loantermLabel3)
                        .addComponent(loantermTextField2)
                        .addComponent(loancalculatedTextField5))
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(interestrateTextField3, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(interestrateLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(interestcalculatedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(239, 239, 239)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(calculateButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(clearjButton8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGap(108, 108, 108))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(30, 30, 30)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(loantermLabel3)
                                .addComponent(interestrateLabel5)
                                .addComponent(mortgageLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(loantermTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(interestrateTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(mortgageTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(20, 20, 20))
                        .addComponent(calculateButton7, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addGap(40, 40, 40)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(jLabel11)
                        .addComponent(jLabel7))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(loancalculatedTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(interestcalculatedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mortgagecalculatedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(clearjButton8)
                    .addContainerGap(101, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
     
        private void mortgagecalculatedTextField4ActionPerformed(java.awt.event.ActionEvent evt) {                                                             
           
          //calculates the mortgage payment amount based on amount entered by user // TODO add your handling code here:
        }                                                            
    
        private void calculateButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                                 
            double intRates = 0;
            //initiates the monthly interest rate
            //initiates the mortgage payment
            //initiates interest paid
            //initiates principal paid
            double monIntRate = intRates/12; //interest rate divided by 12 months equals the monthly interest rate
            double loanTerm = 0;
            double totMons = loanTerm*12; //term of loan multiplied by 12 months equals total months of term
            double amLoanOne = (double)(mortgageTextField1.getText());
            //initiates the amount of loan balance after initial amount
            double monPay = (double)(mortgageTextField1.getText())*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
          mortgagecalculatedTextField4.setText(monPay + "Mortgage Amount");
            //calculates the mortgage payment
            double intsPaid = (double)(mortgageTextField1.getText()*monIntRate);
            interestcalculatedTextField6.setText(intsPaid + "Interest Amount");
            //calculates the interest paid
            double princPaid = monPay - intsPaid;
            //calculates the principal paid
            double amLoanNxt = (double)(mortgageTextField1.getText()- princPaid);
            loancalculatedTextField5.setText(amLoanNxt + "Loan Amount");
            //calculates the amount of loan balance after initial amount  
           
           
           
        }                                                
    
        private void clearjButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                              
          mortgageTextField1.setText("");
          loantermTextField2.setText("");
          interestrateTextField3.setText("");
          mortgagecalculatedTextField4.setText("");
          loancalculatedTextField5.setText("");
          interestcalculatedTextField6.setText("");
          
          
          
          
         // TODO add your handling code here:
        }                                             
    
        private void mortgageTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                                   
            String amLoanOne = mortgageTextField1.getText(); // TODO add your handling code here:
        }                                                  
    
        private void loantermTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        String loanTerm = loantermTextField2.getText();    // TODO add your handling code here:
        }                                                  
    
        private void interestrateTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                                       
        String intRates = interestrateTextField3.getText();    // TODO add your handling code here:
        }                                                      
    
        private void loancalculatedTextField5ActionPerformed(java.awt.event.ActionEvent evt) {                                                         
       
               
          //calculates the loan balance based on the amount entered by user     // TODO add your handling code here:
        }                                                        
    
        private void interestcalculatedTextField6ActionPerformed(java.awt.event.ActionEvent evt) {                                                             
       
       
      
          //calculates the interest paid with interest rate entered by user     // TODO add your handling code here:
        }                                                            
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new MortgageGUI().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify                     
        private javax.swing.JButton calculateButton7;
        private javax.swing.JButton clearjButton8;
        private javax.swing.JTextField interestcalculatedTextField6;
        private javax.swing.JLabel interestrateLabel5;
        private javax.swing.JTextField interestrateTextField3;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JTextField loancalculatedTextField5;
        private javax.swing.JLabel loantermLabel3;
        private javax.swing.JTextField loantermTextField2;
        private javax.swing.JLabel mortgageLabel1;
        private javax.swing.JTextField mortgageTextField1;
        private javax.swing.JTextField mortgagecalculatedTextField4;
        // End of variables declaration                   
    }

  13. #13
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    required: double
    found: java.lang.String
    at mortgage.MortgageGUI.calculateButton7ActionPerform ed(MortgageGUI.java:211)
    On line 211 (I'm not going to count) you are trying to use a String but the code is expecting a double.

  14. #14
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Java Code:
    double amLoanOne = (double)(mortgageTextField1.getText());
    You cannot cast a String to a double. You need to parse it just like you do with ints (No that doesn't mean using Integer.parseInt. How about you think about it).
    Java Code:
    double loanTerm = 0;
    double totMons = loanTerm*12;
    How will it be possible for totMons to have any other value except 0?

  15. #15
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default GUI build successful!! Thanks!!

    Hi, Junky. I got it to run!! Yayyyyyy!! Thanks.

Similar Threads

  1. Linking Multiple GUIs
    By Penguin Buddha in forum AWT / Swing
    Replies: 11
    Last Post: 04-24-2011, 06:59 AM
  2. Problem with GUIS
    By sunde887 in forum New To Java
    Replies: 1
    Last Post: 02-17-2011, 08:18 AM
  3. NOOB needs help with buttons and events, GUIs.
    By simonsays415 in forum New To Java
    Replies: 12
    Last Post: 07-22-2010, 06:02 AM
  4. Can you create two GUIs?
    By SNPTT in forum New To Java
    Replies: 4
    Last Post: 05-18-2010, 12:08 PM
  5. guis and php
    By paddala in forum Advanced Java
    Replies: 1
    Last Post: 02-18-2010, 03:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •