Good morning all. I've run into a slight stumbling block with some code I'm writing. I'm sure you've all seen the numerous Mortgage Calculator threads so I hope you're not too sick of them yet.

Basically, I need my code to first ask the user for a decision, then based upon that decision display one of two windows. I've already got one window that I need from the previous code. My problem is creating the second window. I want it to look and act almost identically to the first window. The difference being where the combo box is in the first, there would instead be text fields for the user to input that information. From there it would act exactly the same.

Your help is sincerely appreciated.

import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.awt.event.*;



public class PRG421Week4 extends JFrame implements ActionListener, ItemListener {
    private static boolean test;

    double loanBalance;                                                         //Initialize loanBalance Variable
    double userAmount ;                                                         //Initialize userAmount Variable
    double userInterest;                                                        //Initialize userInterest Variable
    double userTerm;                                                            //Initialize userTerm Variable
    int months;                                                                 //Initialize months Variable
    double annualInterestRate [] = {5.35, 5.5, 5.75};                           //Initialize APR Array
    int years [] = {7, 15, 30};                                                 //Initialize Term Array
    double monthlyInterest;                                                     //Initialize monthlyInterest Variable
    double loanMonths;                                                          //Initialize loanMonths Variable
    double monthlyPayment;                                                      //Initialize monthlyPayments Variable
    double currentMonthInterest;                                                //Initialize currentMonthInterest Variable
    double currentMonthPrinciple;                                               //Initialize currentMonthPrinciple Variable
    int answer;

    DecimalFormat eachPayment = new DecimalFormat ("$###,##0.00");

	//Define Row 1 Components
	JPanel row1 = new JPanel();
	JLabel lAmount = new JLabel(" Mortgage: $", JLabel.LEFT);
	JTextField tAmount = new JTextField(10);

	//Define Combo for Interest and Term
	JLabel lcombo = new JLabel ("Term/Interest");
	String cboData[] = {"Select Term","7 years at 5.35%","15 years at 5.50%","30 years at 5.75%"};
	JComboBox comboTermInterest = new JComboBox(cboData);

	//Define Payment Text Area
	JLabel lPayment = new JLabel("Payment:");
	JTextField tPayment = new JTextField(10);

	//Define Row 2 Components
	JPanel row2= new JPanel(new BorderLayout());
	String pad = "                                      ";
	JLabel lHeader = new JLabel("Payment #"+pad+"Payment:"+pad+"Interest Paid:"+pad+"New Balance:");
	JTextArea tResults = new JTextArea(10, 53);
	JScrollPane tPane = new JScrollPane(tResults);

	//Define Row 3 Components
	JPanel row3 = new JPanel(new GridLayout(1,3,75,1));
	JButton calculateButton = new JButton("Calculate");
	JButton clearButton = new JButton("Clear");
	JButton exitButton = new JButton("Exit");

	//Define GUI Window
	public PRG421Week4 (){
            super("McBride Mortgage Calculator");
            
                JFrame usercalculation = new JFrame();
                usercalculation.setTitle("McBride Mortgage Calculator");
                usercalculation.setSize(300,300);
                usercalculation.setDefaultCloseOperation(usercalculation.EXIT_ON_CLOSE);
                usercalculation.setVisible(false);


            setBounds(350, 250, 600, 250);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            row1.add(lAmount);
            row1.add(tAmount);
            row1.add(lcombo);
            row1.add(comboTermInterest);
            row1.add(lPayment);
            row1.add(tPayment);

            tPayment.setEditable(false);

            tPane.setPreferredSize(new Dimension(610,200));

            row2.add(lHeader,BorderLayout.NORTH);
	    row2.add(tPane,BorderLayout.CENTER);

	//Create Calculate Button
	    comboTermInterest.addItemListener(this);
	    calculateButton.addActionListener(this);
	    clearButton.addActionListener(this);
	    exitButton.addActionListener(this);

            row3.add(exitButton);
            row3.add(clearButton);
            row3.add(calculateButton);

            getContentPane().add(row1,BorderLayout.NORTH);
	    getContentPane().add(row2,BorderLayout.CENTER);
	    getContentPane().add(row3,BorderLayout.SOUTH);

	    pack(); }

        //Events for Combo Box
	public void itemStateChanged(ItemEvent event) {
            Object select = event.getItem();
            String selection = select.toString();
            if (selection == cboData[0]) {
            }
            if (selection == cboData[1]) {
	       userInterest = annualInterestRate [0];
	       userTerm = years [0];
            }
            if (selection == cboData[2]) {
	       userInterest = annualInterestRate [1];
	       userTerm = years [1];
            }
            if (selection == cboData[3]) {
	       userInterest = annualInterestRate [2];
	       userTerm = years [2];
            }
        }
	//Define Events for Buttons
	public void actionPerformed(ActionEvent e) {
            if (e.getSource() == calculateButton)
	    {
	    userAmount = Double.parseDouble(tAmount.getText());
            CalculateMonthlyPayment() ;
	    tPayment.setText( eachPayment.format( monthlyPayment)+"    ");

	    repaint();
	    loanMonths = userTerm * 12;                                         //Calculate # of Payments
	    loanBalance = userAmount;

            for (months = 1; months <= loanMonths; months++) {
                monthlyInterest = userInterest / (1200.00);                     //Monthly Interest
	        currentMonthInterest = loanBalance * monthlyInterest;           //Calculate Interest Payment
	        currentMonthPrinciple = monthlyPayment - currentMonthInterest;  //Calculate Principle Payment
	        loanBalance = loanBalance - currentMonthPrinciple;              //Calculate Balance

                //Display Results
                tResults.append("" + months + "\t\t" + eachPayment.format(monthlyPayment)
	        + "\t\t" + eachPayment.format(currentMonthInterest)
	        + "\t\t"
	        + eachPayment.format(loanBalance) + "\n");	        }
	     }
	     else if (e.getSource() == clearButton) {
	        //clear fields
	        tAmount.setText ("");
	        tPayment.setText("");
	        userAmount = 0;
	        tPayment.setText("");
	        tResults.setText("");
	     }
                else if (e.getSource() == exitButton) {
                    System.exit(0);
	        }           
	}
	//Calculate the Ammortization
	double CalculateMonthlyPayment(){
	return monthlyPayment = (userAmount * ((1 + (userInterest*.01)/12)-1) / (1-(Math.pow(1 + (userInterest/1200),-(userTerm*12)))));
	}

	public static void main(String[] args){
            test = true;
            while(test){
              String question = JOptionPane.showInputDialog("To cacluate a loan using unspecified Interest and Term type, '1'. To calculate a loan using specifed loan options, type '2'");
              int answer = Integer.parseInt(question);
              if (answer == 1){

                  //???????????????
              }
            else{
                new PRG421Week4().setVisible(true);
                test = false;
             }
        }
    }
}

Recommended Answers

All 25 Replies

Can you explain what your problem is with creating a window?
Your current code creates one, so you know the code to use.
You could create a new class that extends JFrame, create it, initialize it and set it visible.

I guess the problem is that I don't know where in the code to start building the new window. No matter where I try, I get errors. Almost like I need to alter the original code first and then start the new window. Just would rather not do that.

I get errors.

Perhaps the errors could be corrected.

Perhaps the errors could be corrected.

Ok I went back and added some code for a second Window (Window2). However, I get an error in Main when I try to call it and set it visible. Says "non static variable this cannot be referenced from a static context".

Here is the code...

/** PRG421 Week 3 Assignment
 *  SR-mf-003 Change Request #5
 *  by Michael Hill
 *  Edited September 27, 2010
 */

import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.awt.event.*;

public class PRG421Week3 extends JFrame implements ActionListener, ItemListener {
    private static boolean test;
    double loanBalance;                                                         //Initialize loanBalance Variable
    double userAmount ;                                                         //Initialize userAmount Variable
    double userInterest;                                                        //Initialize userInterest Variable
    double userTerm;                                                            //Initialize userTerm Variable
    int months;                                                                 //Initialize months Variable
    double annualInterestRate [] = {5.35, 5.5, 5.75};                           //Initialize APR Array
    int years [] = {7, 15, 30};                                                 //Initialize Term Array
    double monthlyInterest;                                                     //Initialize monthlyInterest Variable
    double loanMonths;                                                          //Initialize loanMonths Variable
    double monthlyPayment;                                                      //Initialize monthlyPayments Variable
    double currentMonthInterest;                                                //Initialize currentMonthInterest Variable
    double currentMonthPrinciple;

    DecimalFormat eachPayment = new DecimalFormat ("$###,##0.00");;

	//Define Row 1 Components
	JPanel row1 = new JPanel();
	JLabel lAmount = new JLabel(" Mortgage: $", JLabel.LEFT);
	JTextField tAmount = new JTextField(10);

	//Define Combo for Interest and Term
	JLabel lcombo = new JLabel ("Term/Interest");
	String cboData[] = {"Select Term","7 years at 5.35%","15 years at 5.50%","30 years at 5.75%"};
	JComboBox comboTermInterest = new JComboBox(cboData);

	//Define Payment Text Area
	JLabel lPayment = new JLabel("Payment:");
	JTextField tPayment = new JTextField(10);

	//Define Row 2 Components
	JPanel row2= new JPanel(new BorderLayout());
	String pad = "                                      ";
	JLabel lHeader = new JLabel("Payment #"+pad+"Payment:"+pad+"Interest Paid:"+pad+"New Balance:");
	JTextArea tResults = new JTextArea(10, 53);
	JScrollPane tPane = new JScrollPane(tResults);

	//Define Row 3 Components
	JPanel row3 = new JPanel(new GridLayout(1,3,75,1));
	JButton calculateButton = new JButton("Calculate");
	JButton clearButton = new JButton("Clear");
	JButton exitButton = new JButton("Exit");

	//Define GUI Window
	public PRG421Week3(){
            super("McBride Mortgage Calculator");

            setBounds(350, 250, 600, 250);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            row1.add(lAmount);
            row1.add(tAmount);
            row1.add(lcombo);
            row1.add(comboTermInterest);
            row1.add(lPayment);
            row1.add(tPayment);

            tPayment.setEditable(false);

            tPane.setPreferredSize(new Dimension(610,200));

            row2.add(lHeader,BorderLayout.NORTH);
	    row2.add(tPane,BorderLayout.CENTER);

	//Create Calculate Button
	    comboTermInterest.addItemListener(this);
	    calculateButton.addActionListener(this);
	    clearButton.addActionListener(this);
	    exitButton.addActionListener(this);

            row3.add(exitButton);
            row3.add(clearButton);
            row3.add(calculateButton);

            getContentPane().add(row1,BorderLayout.NORTH);
	    getContentPane().add(row2,BorderLayout.CENTER);
	    getContentPane().add(row3,BorderLayout.SOUTH);

            test=false;

	    pack(); }

        //Events for Combo Box
	public void itemStateChanged(ItemEvent event) {
            Object select = event.getItem();
            String selection = select.toString();
            if (selection == cboData[0]) {
            }
            if (selection == cboData[1]) {
	       userInterest = annualInterestRate [0];
	       userTerm = years [0];
            }
            if (selection == cboData[2]) {
	       userInterest = annualInterestRate [1];
	       userTerm = years [1];
            }
            if (selection == cboData[3]) {
	       userInterest = annualInterestRate [2];
	       userTerm = years [2];
            }
        }

	//Define Events for Buttons
	public void actionPerformed(ActionEvent e) {
            if (e.getSource() == calculateButton)
	    {
	    userAmount = Double.parseDouble(tAmount.getText());
            CalculateMonthlyPayment() ;
	    tPayment.setText( eachPayment.format( monthlyPayment)+"    ");

	    repaint();
	    loanMonths = userTerm * 12;                                         //Calculate # of Payments
	    loanBalance = userAmount;

            for (months = 1; months <= loanMonths; months++) {
                monthlyInterest = userInterest / (1200.00);                     //Monthly Interest
	        currentMonthInterest = loanBalance * monthlyInterest;           //Calculate Interest Payment
	        currentMonthPrinciple = monthlyPayment - currentMonthInterest;  //Calculate Principle Payment
	        loanBalance = loanBalance - currentMonthPrinciple;              //Calculate Balance

                //Display Results
                tResults.append("" + months + "\t\t" + eachPayment.format(monthlyPayment)
	        + "\t\t" + eachPayment.format(currentMonthInterest)
	        + "\t\t"
	        + eachPayment.format(loanBalance) + "\n");	        }
	     }
	     else if (e.getSource() == clearButton) {
	        //clear fields
	        tAmount.setText ("");
	        tPayment.setText("");
	        userAmount = 0;
	        tPayment.setText("");
	        tResults.setText("");
	     }
                else if (e.getSource() == exitButton) {
                    System.exit(0);
	        }
	}

	//Calculate the Ammortization
	double CalculateMonthlyPayment(){
	return monthlyPayment = (userAmount * ((1 + (userInterest*.01)/12)-1) / (1-(Math.pow(1 + (userInterest/1200),-(userTerm*12)))));
	}

public class Window2 extends JFrame {

            public Window2 (){
                super("McBride Mortgage Calculator");

            setBounds(350, 250, 600, 250);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            row1.add(lAmount);
            row1.add(tAmount);
            row1.add(lcombo);
            row1.add(comboTermInterest);
            row1.add(lPayment);
            row1.add(tPayment);

            tPayment.setEditable(false);

            tPane.setPreferredSize(new Dimension(610,200));

            row2.add(lHeader,BorderLayout.NORTH);
	    row2.add(tPane,BorderLayout.CENTER);

	//Create Calculate Button
	    comboTermInterest.addItemListener((ItemListener) this);
	    calculateButton.addActionListener((ActionListener) this);
	    clearButton.addActionListener((ActionListener) this);
	    exitButton.addActionListener((ActionListener) this);

            row3.add(exitButton);
            row3.add(clearButton);
            row3.add(calculateButton);

            getContentPane().add(row1,BorderLayout.NORTH);
	    getContentPane().add(row2,BorderLayout.CENTER);
	    getContentPane().add(row3,BorderLayout.SOUTH);

	    pack(); }
            }

    public static void main(String[] args){
            test = true;
            while (test){
            String question = JOptionPane.showInputDialog("To Calculate A Loan Using Unspecified Options, Type 1. To Calculate A Loan Using Specified Options, Type 2");
            double answer = Integer.parseInt(question);
            if (answer == 1){
                new Window2().setVisible(true);
            }
            else if (answer == 2){
            new PRG421Week3().setVisible(true);
            }
            else{
                test=true;
            }
         }
    }
}

Where is the full text of the error message? The line number of the error?

Where is the full text of the error message? The line number of the error?

Line 202
Attached a screenshot...

One solution is to make the Window2 class static.

Which class is the main method in?

One solution is to make the Window2 class static.

Which class is the main method in?

It gave me an error "modifier not allowed here" when I tried to make "public Window2(){" static.

This may show how noob I am in this, but I'm thinking Main belongs to PRG421Week3? Can you look at the code and tell?

You put the static before the class:
static class Window2

You put the static before the class:
static class Window2

Okay I tried that as well. That removed the error from the main() but created errors in public Window2(){. Looks like the same error as in main. See the screenie...

The variables in the error message are not in the static context the Window2 class is in. They only exist in when there is an instance of the enclosing object created.

So back to the drawing board on your design. How can the Window2 constructor access variables that do NOT exist unless there is an instance of the PRG421Week3 class created to hold them? The main method creates either one or the other of those two classes. How can the Window2 class then use values from the PRG421Week3 class that has no object in existence?

Yeah I picked up on that after I made the post. Just had to copy into the Window2 contructor. However, now I'm getting an error when I run the application...

Exception in thread "main" java.lang.ClassCastException: PRG421Week3$Window2 cannot be cast to java.awt.event.ItemListener
at PRG421Week3$Window2.<init>(PRG421Week3.java:206)
at PRG421Week3.main(PRG421Week3.java:228)
Java Result: 1

Casting the listeners is a BAD idea. You should let the compiler test if the variable is of the correct type.

More on your design. If you want to have two windows with a lot of common parts, use three classes. The primary class would have all the components defined in it. The other two classes would extend the primary class. Add a new class Window1 that extends the primary class and that builds a GUI just like Window2 does. Leave the listeners in the primary class. The main() method would then either create a new Window1 or a new Window2. The code in the current PRG421Week4 constructor would go in the Window1 constructor. With a few more adjustments that could allow you to have two windows that are very similiar.

Casting the listeners is a BAD idea. You should let the compiler test if the variable is of the correct type.

More on your design. If you want to have two windows with a lot of common parts, use three classes. The primary class would have all the components defined in it. The other two classes would extend the primary class. Add a new class Window1 that extends the primary class and that builds a GUI just like Window2 does. Leave the listeners in the primary class. The main() method would then either create a new Window1 or a new Window2. The code in the current PRG421Week4 constructor would go in the Window1 constructor. With a few more adjustments that could allow you to have two windows that are very similiar.

Casting the listeners is a BAD idea. You should let the compiler test if the variable is of the correct type.

More on your design. If you want to have two windows with a lot of common parts, use three classes. The primary class would have all the components defined in it. The other two classes would extend the primary class. Add a new class Window1 that extends the primary class and that builds a GUI just like Window2 does. Leave the listeners in the primary class. The main() method would then either create a new Window1 or a new Window2. The code in the current PRG421Week4 constructor would go in the Window1 constructor. With a few more adjustments that could allow you to have two windows that are very similiar.

Okay... First, thanks to all that have helped thus far. Because the code seemed to be confusing not only me, but experts as well, I went back to the drawing board. I've redesigned and written the code to use only one window. Now, my question is this... I'm having trouble getting the application to choose what to do based on an array. Basically, I have a combo box set up to pull from an array. I have an IF statement set so that if a particular choice is made that it will pull the user input from two textfields to calculate the code. However, when I select the option in the combo box for "own terms" and type figures into the appropriate textfields, it does not calculate anything. Here's the code I have so far...

import javax.swing.*;		// includes the Swing class
import java.awt.*;		// includes the AWT class
import java.awt.event.*;        // includes the class to recognize events in the GUI
import java.text.*;             // includes the class NumberFormat for currency formatting*/


public class PRG421Week3 extends JFrame implements ActionListener
{

	JTextField tMortgageAmount;             // the field used for input of the principle
	JTextField tMonthlyPayment;             // the field used to output monthly payment
        JTextField tTerm;                       // the field used for input of the user's term
        JTextField tRate;                       // the field used for input of the user's interest
        JComboBox cbMortgageLoanOptions;        // the Combo Box to display mortgage terms options
	JTextArea taLoanDetails;                // the text area to output loan details
        JScrollPane spLoanDetails;              // the wrapper for the loan details area
	protected JButton bCalculate;           // the button needed on the screen
        protected JButton bQuit;                // the button used to quit the program
        JLabel lMessages;                       // the label used for any messages to be sent to the user
	DecimalFormat df = new DecimalFormat("$###.00");    // setting locale and format for currency
        //declaration of variables for internal use
        private int mortgage;                               //principal
        private int years;                                  //term
        private double rate;                                //interest rate
        private double monthlyPaymentAmt;                   //mortgage payment amount
        private double remainingBalance;                    //remaining balance
        int[] arrLoanTerm = {7,15,30,0};
        double[] arrLoanRate = {5.35,5.5,5.75,0};
        private double userRate;
        private double userRate2;
        private int userTerm;
        private int userTerm2;

        /*
         * The constructor for the GUI that is used to put everything together
         */
        public PRG421Week3() {

            // Separate Panel used for Messages to user
            JPanel pMessages = new JPanel();
            pMessages.setLayout(new FlowLayout());
            pMessages.add(lMessages = new JLabel("Calculate Mortgage"));

            String[] loanOptions = {"7 years at 5.35%","15 years at 5.5%","30 years at 5.75%","Own Terms"};

            // Separate Panel used for all text field labels
            JPanel pLabels = new JPanel();
            pLabels.setLayout(new GridLayout(6, 1));
            pLabels.add(new JLabel("   Enter Loan Amount"));
            pLabels.add(new JLabel("   Choose your mortgage terms"));
            pLabels.add(new JLabel("   Term"));
            pLabels.add(new JLabel("   Interest Rate"));
            pLabels.add(new JLabel("   Your Monthly Payment is:"));
            
            taLoanDetails = new JTextArea(30,20);
            // Separate Panel used for all text fields
            JPanel pFields = new JPanel();
            pFields.setLayout(new GridLayout(6, 1));
            pFields.add(tMortgageAmount = new JTextField(12));
            pFields.add(cbMortgageLoanOptions = new JComboBox(loanOptions));
            pFields.add(tTerm = new JTextField(12));
            pFields.add(tRate = new JTextField(12));
            pFields.add(tMonthlyPayment = new JTextField(12));
            
            // Combining the labels and text fields into an area together
            JPanel pData = new JPanel();
            pData.setLayout(new BorderLayout());
            pData.add(pLabels, BorderLayout.WEST);
            pData.add(pFields, BorderLayout.CENTER);

            // Separate area on the screen for the buttons
            JPanel pButtons = new JPanel();
            pButtons.setLayout(new FlowLayout());
            pButtons.add(bCalculate = new JButton("Calculate"));
            pButtons.add(bQuit = new JButton("Quit"));

            // Setting properties for the Scroll Pane
            spLoanDetails = new JScrollPane(taLoanDetails);
            spLoanDetails.setPreferredSize(new Dimension(250,375));
            spLoanDetails.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

            // Bringing things together into the GUI
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(pMessages, BorderLayout.NORTH);
            getContentPane().add(pData, BorderLayout.CENTER);
            getContentPane().add(pButtons, BorderLayout.EAST);
            getContentPane().add(spLoanDetails,BorderLayout.SOUTH);

            // Register listeners with the buttons
            bCalculate.addActionListener(this);
            bQuit.addActionListener(this);

            tMonthlyPayment.setEnabled(false);  // this is an output only field
            taLoanDetails.setEnabled(false);    // this is an output only area
        }

        //method for calculating monthly payments
        public void MonthlyPaymentCalculation(){
            monthlyPaymentAmt = ((rate / 12) * mortgage) / (1- (Math.pow (1+ (rate / 12), (years * -12))));
        }

        public void LoanDetailsCalculation(){
            taLoanDetails.append("Month No.\tMonthly Payment\tRemaining Balance\tInterest Paid\n");
            for (int i = 1; i <= years*12; i++){
                double thisPaymentInterest = (rate / 12) * remainingBalance;         // calculate the interest for the current payment
                double thisPaymentPrinciple = monthlyPaymentAmt - thisPaymentInterest;     // calculate the principle amount for the current payment
                remainingBalance = remainingBalance - thisPaymentPrinciple;             // calculate the remaining total balance
                taLoanDetails.append(i + "\t" + df.format(monthlyPaymentAmt) + "\t\t" + df.format(remainingBalance) + "\t\t" + df.format(thisPaymentInterest) + "\n");  // output the monthly amounts
            }
        }

        //button press event handler
        public void actionPerformed(ActionEvent e){
            if (e.getSource() == bCalculate){
                try{
                    // This section extracts values from the field on the GUI to do the calculation
                    // It is in a try catch block to catch any runtime errors coming out of
                    // erroneous user input
                    String userInput;
                    userInput = tMortgageAmount.getText();
                    mortgage = Integer.parseInt(userInput);
                    rate = arrLoanRate[cbMortgageLoanOptions.getSelectedIndex()]/100 ;
                    years = arrLoanTerm[cbMortgageLoanOptions.getSelectedIndex()];
                    if (years == 3){
                        String userRate;
                        userRate = tRate.getText();
                        userRate2 = Double.parseDouble(userRate);
                        String userTerm;
                        userTerm = tTerm.getText();
                        userTerm2 = Integer.parseInt(userTerm);
                        rate = userRate2 / 100;
                        years = userTerm2;
                        MonthlyPaymentCalculation();
                    }
 else{
                    MonthlyPaymentCalculation();
                    tMonthlyPayment.setText(String.valueOf(df.format(monthlyPaymentAmt)));
                    lMessages.setText("Calculate Mortgage");
                    remainingBalance = mortgage;
                    taLoanDetails.setText("");
                    LoanDetailsCalculation();
                    repaint();
                    }
                } catch (Exception ex) {
                    lMessages.setText("There was an error in one of your entries. Please correct and try again.");
                }
            } else {
                System.exit(0);
            }
        }

       public static void main(String[] args){
            // create new frame object
            PRG421Week3 frame = new PRG421Week3();
            //set frame title
            frame.setTitle("McBride Financial Services Mortgage Payment Calculator");
            frame.setSize(800,600);					// set window size
            frame.setVisible(true);					// set window to visible
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	// tell window how it closes by default
            frame.setVisible(true);					// make frame visible
       }

}

it does not calculate anything

What is supposed to cause it to calculate anything?
Is there method that should be called?
Is there a listener that is not being called?


Have you tried debugging the code to see where the execution flow goes and where it doesn't go? Add some print outs to show what is happening.

I just compiled and executed it and got output. ???

What is supposed to cause it to calculate anything?
Is there method that should be called?
Is there a listener that is not being called?


Have you tried debugging the code to see where the execution flow goes and where it doesn't go? Add some print outs to show what is happening.

I just compiled and executed it and got output. ???

Well, the calculate button causes it to call the MonthlyPaymentCalculation after setting all the variables in the formula.

It does work like a charm when you use one of the presets from the combobox. However, if you just choose "Own Terms" and type in your interest rate and term, it does nothing. Well, I shouldn't say nothing, it displays the heading for the ammortization schedule and prints a square in the "payment" textfield.

Have you tried debugging it by using print outs to show the variables as their values change? Don't wait for me to find it and tell you. I'll make suggestions that could help you find the problem.

Have you tried debugging it by using print outs to show the variables as their values change? Don't wait for me to find it and tell you. I'll make suggestions that could help you find the problem.

Honestly, I'm just really learning Java and this NetBeans application. I just tried using the debugger but I'm not really sure how to use it. I'll keep trying.

*Edit
I just tried the Debugger using a small tutorial. I still don't think I'm using it quite right, but I did get a little information out of it. When I DO NOT use the combobox and instead input my own numbers... The returned product monthlyPaymentAmt is NaN :(

I found the problem after adding two print statements to show the values of some controlling variables.
I don't have an IDE with a debugger. I use print outs.

Holy Crap it works!! :)

Glad you got it working.

Did you find the problem being that in my IF statement, I had the wrong value to compare to??

Thanks a ton for all your help!

Yes, the years is 0 for the do it youself comps.

Note on the code:
You have two parallel arrays that must be kept in sync (combo box text and the years array). Either add notes to the code telling of this potential problem or change the design.

Thanks again for all your help, Norm. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.