Mortgage gui errors


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Mortgage gui errors

  1. #1
    Join Date
    Mar 2010
    Posts
    1

    Mortgage gui errors

    I am having an issue tieing all of my code together there is a discription of what my code is supposed to do, but when I compile I get this error.<identifier>expected Calculate = new JButton ("Calculate");
    ????wanted to see if someone could help????thank you for looking!!!!!
    Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount
    from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:

    - 7 years at 5.35%
    - 15 years at 5.5%
    - 30 years at 5.75%

    Use an array for the mortgage data for the different loans.
    Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan.
    Allow the user to loop back and enter a new amount and make a new selection or quit.
    Please insert comments in the program to document the program.
    */

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.text.DecimalFormat;
    
    public class MCA extends JPanel {
    
    	public static void main(String[] args) {
    
    				// GUI Components: Text Fields / Labels
              final JTextField loanField = new JTextField(15);
    			  JLabel loanLabel = new JLabel();
    	      final JTextField interestField = new JTextField();
    			  JLabel interestLabel = new JLabel();
              final JTextField paymentField = new JTextField(10);
    			  JLabel paymentLabel = new JLabel();
    
    			   // GUI Components: Buttons
    		JButton Reset = new JButton("Reset");
    		JButton Calculate = new JButton("Calculate");
    		JButton Exit = new JButton("Exit");
    		JButton showItButton = new JButton("Show It");
    
    				//Window definition
    		JFrame aWindow = new JFrame("Amortization Calculator");			// Set the window variable
    		int windowWidth = 500; 											// Window width in pixels
    		int windowHeight = 400; 										// Window height in pixels
    		aWindow.setBounds(75, 125, 										// Set window position
    						  windowWidth, windowHeight);					// Set window size
    		aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);			// Set close behavior
    
    				//GUI Layout - Row creation and component population:
            Box Row1 = Box.createHorizontalBox();
    			Row1.add (loanLabel);
    			Row1.add (Box.createRigidArea (new Dimension(10,0)));
    			Row1.add (loanField);
    		Box Row2 = Box.createHorizontalBox();
    			Row2.add (interestLabel);
    			Row2.add (Box.createRigidArea (new Dimension (10,0)));
    			Row2.add (interestField);
    	    Box Row3 = Box.createHorizontalBox();
    			Row3.add (paymentLabel);
    			Row3.add (Box.createRigidArea (new Dimension (10,0)));
    			Row3.add (paymentField);
    		Box bottom = Box.createHorizontalBox();
    		  JPanel bottomPanel = new JPanel();
    			bottomPanel.add(Reset);
    			bottomPanel.add(Calculate);
    			bottomPanel.add(Exit);
    			bottomPanel.add(ShowIt);
    		Box top = Box.createVerticalBox();
    
    			top.add (Box.createRigidArea(new Dimension(0,20)));
    			top.add (Row4);
    			top.add (Box.createVerticalStrut(15));
    		Container content = aWindow.getContentPane();
    				  content.setLayout (new BorderLayout());
    				  content.add (top, BorderLayout.CENTER);
    				  content.add (bottomPanel, BorderLayout.SOUTH);
    		      aWindow.setVisible (true);
    		     loanLabel.setText ("Loan Amount: $");
    				loanLabel.setLabelFor (loanField);
                  interestLabel.setText ("Interest rate percentage:");
    				interestLabel.setLabelFor (interestField);
    				paymentField.setEditable (false);
    				paymentLabel.setText ("Monthly Loan Payment: $");
    				paymentLabel.setLabelFor (paymentField);
               //Action Listeners / Button Operation
    		Reset.addActionListener (new ActionListener() {
    			public void actionPerformed (ActionEvent evt) {
                      paymentField.setText ("");
    
    			}
    		});
         }
    
    	private JPanel createFeatureDialogBox() {
    	        final int numButtons = 1;
    	        JRadioButton[] radioButtons = new JRadioButton[numButtons];
    	        final ButtonGroup group = new ButtonGroup();
    
    	        JButton showItButton = null;
    
            final String pickOneCommand = "pickone";
    
            radioButtons[0] = new JRadioButton("Choose a loan term");
            radioButtons[0].setActionCommand(pickOneCommand);
    		 for (int i = 0; i < numButtons; i++) {
    		             group.add(radioButtons[i]);
    		         }
    		         radioButtons[0].setSelected(true);
    
    		         showItButton = new JButton("Show it!");
    		         showItButton.addActionListener(new ActionListener() {
    		             public void actionPerformed(ActionEvent evt) {
    		                 String command = group.getSelection().getActionCommand();
    
    		                 //pick one of many
    		                 if (command == pickOneCommand) {
    		                     Object[] possibilities = {"7", "15", "30"};
    		                     int s = (String)JOptionPane.showInputDialog(
    		                                         frame,
    		                                         "Choose a loan term:\n"
    		                                         +"Customized Dialog",
    		                                         JOptionPane.PLAIN_MESSAGE,
    		                                         icon,
    		                                         possibilities,
    		                                         "");
    
    		                     //If a string was returned, say so.
    		                     if ((s != null) && (s.length() > 0)) {
    
                                   return;
    		                     }
                          }
    			 }
    		   Calculate = new JButton ("Calculate");
               Calculate.addActionListener (new ActionListener() {
    			public void actionPerformed (ActionEvent evt)
    			{
    				{
    				   int[]T1= (s);                                    // multiplied the given terms by 12 to break them down into years
    				     P = Double.parseDouble (loanField.getText());
    				     I = Double.parseDouble (interestField.getText());
    
                        DecimalFormat D = new DecimalFormat("$#.##");
                        for (int i = 0; i <T1.length; i++)                          //for function of the array
    					        {
    					        for(int j = 1;j<=12;j++)
    					        {
    
    					         double I,P,A,MI,MP,A2,R1,MR,MR1,P2;
    					         int T2= T1[i];
    					             R1=I;
    								 MR=(I/1200);                                    //calculates the monthly interest on the loan
    								 MR1=(Math.pow((1+MR),T2)-1)
    										/ (MR*Math.pow((1+MR),T2));
    					             P2=(P/MR1);
    					             int yrs =(int)(T2/12);
    
    
    		        paymentField.setText(""+D.format(MR1));
    			}
    		}
    
    		            /* MI=(A1*MR);                                           //amount paid towards interest
    				     MP=(P2-MI);                                           //amount paid towards principal
                         A1=(A1-MP);*/
    
    	       }
             }
          });
    
                Exit.addActionListener (new ActionListener() {
     			public void actionPerformed (ActionEvent event) {
     				System.exit(1);
     					}
    		});
         }
      }
    }
    }
    }

  2. #2
    Join Date
    May 2004
    Posts
    40
    You'd probably get a little more response if you posted what problems you're having with this code. If you're getting compile errors or runtime exceptions, post the full text of these errors as well.

  3. #3
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    You are getting this error because you have not given a datatype to Calculate where you declare it near the end of your code - by the way, do you see that you have declared a JButton by the name Calculate early in method main?

Similar Threads

  1. Mortgage calculator with GUI
    By karinmorena in forum Java
    Replies: 1
    Last Post: 02-25-2008, 02:16 PM
  2. Code Help with GUI Mortgage Calculator
    By drewdat7001 in forum Java
    Replies: 4
    Last Post: 12-20-2006, 12:55 AM
  3. Help With GUI Mortgage Calculator
    By drewdat7001 in forum Java
    Replies: 1
    Last Post: 10-29-2006, 11:34 PM
  4. Replies: 7
    Last Post: 03-07-2006, 04:34 PM
  5. Replies: 2
    Last Post: 09-04-2001, 08:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center