Solved

Out of ideas

Posted on 2006-11-19
14
233 Views
Last Modified: 2010-03-31
A friend asked me if I could help debug her code(blind leading the blind), I got it down to two erros, can you fix this for us. The error is "}"expecting , I did what I can so far , you know the easy errors missing semie colons and such, but I am out of ideas, thank you...




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

      public class SADProgram3 extends JPanel //implements ActionListener
      {
            SADProgram3Event HEARME = new SADProgram3Event(this);

//-------------------------------------------------------------
// DEFINE and DIMENSION VARIABLES AND BUTTON FUNCTIONS
//-------------------------------------------------------------

                                                                  // Buttons
                                                 JButton Calculate;
             JButton Clear;
       JButton Exit;
                  
                                                                  
                                                                  
            private JButton Calculate = new JButton("Calculate");
            private JButton Clear = new JButton("New Amount");
            private JButton Exit = new JButton("Exit");
                                                                  // text area to hold data;                  
            JTextArea area = new JTextArea(10, 20);
            
                                                                  // action listeners for buttons
            
                        

//-------------------------------------------------------------
// BUILD THE DROP-DOWN MENU
//-------------------------------------------------------------
      
            JMenuBar menuBar;
            JMenuItem item;
            JToolBar toolBar;

//-------------------------------------------------------------
// BUILD THE LAYOUT FLOWS
//-------------------------------------------------------------
            
      public SADProgram3()
      {
      Calculate.addActionListener(HEARME);
            Clear.addActionListener(HEARME);
            Exit.addActionListener(HEARME);

                                                                  // trying to add pains
            
            GridLayout layout = new GridLayout(1, 1, 1, 1);
            Container pane = getContentPane();
            pane.setLayout(layout);
            
                                                                  // build the first layout panel and add label
            JPanel File1 = new JPanel();
            JLabel lblLoanAmount = new JLabel("Type the loan amount here",
            JLabel.CENTER);                         // center the label and set the text field to 10 char length
            JTextField txtLoanAmount = new JTextField(10);
            
            
                                                                  // build the second layout panel and add label
            JPanel File2 = new JPanel();
            JLabel lblIntRate = new JLabel("Type the interest rate here",
            JLabel.CENTER);                         // center the label and set the text field to 10 char length
            JTextField txtIntRate = new JTextField(10);
            
            
                                                                  // build the third layout panel and add label
            JPanel File3 = new JPanel();
            JLabel lblTerm = new JLabel("Type the loan term here",
            JLabel.CENTER);                         // center the label and set the text field to 10 char length
            JTextField txtTerm = new JTextField(10);
            

                                                                  // build the fourth layout panel and add label
            JPanel File4 = new JPanel();
            JLabel lblPayment = new JLabel("Your monthly payment",
            JLabel.CENTER);                         // center the label and set the text field to 10 char length
            JTextField txtPayment = new JTextField(10);
                        
            
//-------------------------------------------------------------
// ADD PAINS TO FRAMES
//-------------------------------------------------------------


                                                            // layout manager for layout 1 Loan Amount
      FlowLayout mgr = new FlowLayout(FlowLayout.CENTER, 15, 15);
      File1.setLayout(mgr);
      File1.add(lblLoanAmount);
      File1.add(txtLoanAmount);
      pane.add(File1);

                                                            // layout manager for layout 2 Rate
      FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER, 15, 15);
      File2.setLayout(layout2);
      File2.add(lblIntRate);
      File2.add(txtIntRate);
      pane.add(File2);
      
                                                            // layout manager for layout 3 Terms
      FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER, 15, 15);
      File3.setLayout(layout3);
      File3.add(lblTerm);
      File3.add(txtTerm);
      pane.add(File3);
      
                                                            // layout manager for layout 4 Payments
      FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER, 15, 15);
      lblPayment.setEditable(false);
      File4.setLayout(layout4);
      File4.add(lblPayment);
      File4.add(txtPayment);
      pane.add(File4);


                                                            // layout manager for layout 5 Buttons
      FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER, 15, 15);
      File5.setLayout(layout5);
      File5.add(Calculate);
      File5.add(Clear);
      File5.add(Exit);
      pane.add(File4);
      
      
                                                                  // layout manager for layout 6
      FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER, 15, 15);
   File6.setLayout(layout6);
   JScrollPane scrollPane = new JScrollPane(area); // add the text area to
      File6.add(scrollPane);
      pane.add(File6);


//-------------------------------------------------------------
// DEVELOP 3 ITEM MENU BAR AND POPULATE IT
//-------------------------------------------------------------

      JMenuBar bar = new JMenuBar();
      File3.add(bar);
      JMenu menu = new JMenu("Select Fixed Rates and Terms");
      JMenuItem item = new JMenuItem("5.35% at 7 yrs");
      JMenuItem item1 = new JMenuItem("5.50% at 15 yrs");
      JMenuItem item2 = new JMenuItem("5.75% at 30 yrs");
      bar.add(menu);
      menu.add(item);
      menu.add(item1);
      menu.add(item2);
      pane.add(File7);


//-------------------------------------------------------------
// ADD ACTION LISTENERS
//-------------------------------------------------------------


      }      
//-------------------------------------------------------------
// CREATE THE GUI AND SHOW IT
//-------------------------------------------------------------            
             
    private static void createAndShowGUI()
       {
                                                       // create and instantiate new frame, set basic properties
            JFrame frame = new JFrame("Simple Mortgage Calculator by McBride Financial");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setSize(600,600);
            frame.setVisible(true);
            }
            
//-------------------------------------------------------------
// MORTGAGE CALCULATIONS
//-------------------------------------------------------------

                                                 // function to calculate the mortgage
            public void CalculateMortgage()
            {
            
            try             
                                                // declare and initialize variables
                                                // using virtual terminology - no idea how this works
                                                // looked at various Java sites
                  {
                  double LoanAmount = Double.valueOf(virtual.LoanAmount.getText()).doubleValue();
                  double IntRate = Double.valueOf(virtual.IntRate.getText()).doubleValue();
                  int Term = Integer.parseInt(virtual.Term.getText());
                  int Months = (Term * 12);
                  double Payment = 0;
                  double InterestPaid;
                  String MonthlyPayment = new String();
                  NumberFormat currency = NumberFormat.getCurrencyInstance();
                  double I = (IntRate / 100.0 / 12.0);
                  Payment = (LoanAmount * I) / (1 - Math.pow(1 / (1 + I), Months));
                  virtual.MonthlyPayment.setText(currency.format(Payment));

//-------------------------------------------------------------
// AMORTIZATION TABLE ERROR HANDLING
//-------------------------------------------------------------
}



                  catch (NumberFormatException ex) {
                        }
                  }

                  protected void reset() {
                  virtual.LoanAmount.setText(null);
                  virtual.IntRate.setText(null);
                  virtual.Term.setText(null);
                  virtual.Payment.setText(null);
                  virtual.area.setText(null);


//-------------------------------------------------------------
// MAIN
//-------------------------------------------------------------
}

                                                      // calls main and executes createAndShowGui
    public static void main(String[] args)
      {
         javax.swing.SwingUtilities.invokeLater(
                new Runnable()
               {
                   public void run()
                  {
                     createAndShowGUI();
                  }
               }); // END OF MAIN
      }
            
      

0
Comment
Question by:charliebaby
  • 6
  • 5
  • 3
14 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 17976746
Try to add one more closing braces at the end of your codes.

    public static void main(String[] args)
      {
         javax.swing.SwingUtilities.invokeLater(
                new Runnable()
               {
                   public void run()
                  {
                     createAndShowGUI();
                  }
               }); // END OF MAIN
      }
} // LOOK HERE - END OF CLASS
0
 
LVL 2

Expert Comment

by:avsrivastava
ID: 17976764
Are there more classes along with this one?

To solve the '}' missing error, put a '}' at the very end of the program, you have not closed the class definition.

However once you do that a lot of new error will show up(Semantic errors show up once the program is free from Syntax errors)

Some errors:
line 10: SADProgram3Event class must be defined before use; please paste this class as well if your friend has written that as well.

line 17: line 18: line 19:
          JButton Calculate;
          JButton Clear;
          JButton Exit;
these have been declared again just afterwards, delete/comment these lines.

Total 24 errors, will look further into then when you let me know if there are more classes.
0
 
LVL 2

Expert Comment

by:avsrivastava
ID: 17976793
The program is now down to 4 errors; with the first 2 because there is no SADProgram3Event class.
give this a try and let me know if you are unable to solve these.
---------------
SADProgram3.java:10: cannot resolve symbol
symbol  : class SADProgram3Event
location: class SADProgram3
          SADProgram3Event HEARME = new SADProgram3Event(this);
          ^
SADProgram3.java:10: cannot resolve symbol
symbol  : class SADProgram3Event
location: class SADProgram3
          SADProgram3Event HEARME = new SADProgram3Event(this);
                                        ^
SADProgram3.java:58: cannot resolve symbol
symbol  : method getContentPane ()
location: class SADProgram3
          Container pane = getContentPane();
                           ^
SADProgram3.java:120: cannot resolve symbol
symbol  : method setEditable (boolean)
location: class javax.swing.JLabel
     lblPayment.setEditable(false);
               ^
4 errors
-------------------------
 import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
import java.awt.geom.*;

     public class SADProgram3 extends JPanel //implements ActionListener
     {
          SADProgram3Event HEARME = new SADProgram3Event(this);

//-------------------------------------------------------------
// DEFINE and DIMENSION VARIABLES AND BUTTON FUNCTIONS
//-------------------------------------------------------------

                                                       // Buttons
//      JButton Calculate;
//      JButton Clear;
//      JButton Exit;
               
                                                       
                                                       
          private JButton Calculate = new JButton("Calculate");
          private JButton Clear = new JButton("New Amount");
          private JButton Exit = new JButton("Exit");
          JLabel lblLoanAmount;
          JLabel lblIntRate;
          JLabel lblTerm;
          JLabel lblPayment;
                                                 // text area to hold data;              
          JTextArea area = new JTextArea(10, 20);
         
                                                       // action listeners for buttons
         
                   

//-------------------------------------------------------------
// BUILD THE DROP-DOWN MENU
//-------------------------------------------------------------
     
          JMenuBar menuBar;
          JMenuItem item;
          JToolBar toolBar;

//-------------------------------------------------------------
// BUILD THE LAYOUT FLOWS
//-------------------------------------------------------------
         
     public SADProgram3()
     {
     Calculate.addActionListener(HEARME);
          Clear.addActionListener(HEARME);
          Exit.addActionListener(HEARME);

                                                       // trying to add pains
         
          GridLayout layout = new GridLayout(1, 1, 1, 1);
          Container pane = getContentPane();
          pane.setLayout(layout);
         
                                                       // build the first layout panel and add label
          JPanel File1 = new JPanel();
          lblLoanAmount = new JLabel("Type the loan amount here",
          JLabel.CENTER);                     // center the label and set the text field to 10 char length
          JTextField txtLoanAmount = new JTextField(10);
         
         
                                                       // build the second layout panel and add label
          JPanel File2 = new JPanel();
          lblIntRate = new JLabel("Type the interest rate here",
          JLabel.CENTER);                     // center the label and set the text field to 10 char length
          JTextField txtIntRate = new JTextField(10);
         
         
                                                       // build the third layout panel and add label
          JPanel File3 = new JPanel();
          lblTerm = new JLabel("Type the loan term here",
          JLabel.CENTER);                     // center the label and set the text field to 10 char length
          JTextField txtTerm = new JTextField(10);
         

                                                       // build the fourth layout panel and add label
          JPanel File4 = new JPanel();
          lblPayment = new JLabel("Your monthly payment",
          JLabel.CENTER);                     // center the label and set the text field to 10 char length
          JTextField txtPayment = new JTextField(10);
                   
          JPanel File5 = new JPanel();
          JPanel File6 = new JPanel();
          JPanel File7 = new JPanel();
         
//-------------------------------------------------------------
// ADD PAINS TO FRAMES
//-------------------------------------------------------------


                                                  // layout manager for layout 1 Loan Amount
     FlowLayout mgr = new FlowLayout(FlowLayout.CENTER, 15, 15);
     File1.setLayout(mgr);
     File1.add(lblLoanAmount);
     File1.add(txtLoanAmount);
     pane.add(File1);

                                                  // layout manager for layout 2 Rate
     FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER, 15, 15);
     File2.setLayout(layout2);
     File2.add(lblIntRate);
     File2.add(txtIntRate);
     pane.add(File2);
     
                                                  // layout manager for layout 3 Terms
     FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER, 15, 15);
     File3.setLayout(layout3);
     File3.add(lblTerm);
     File3.add(txtTerm);
     pane.add(File3);
     
                                                  // layout manager for layout 4 Payments
     FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER, 15, 15);
     lblPayment.setEditable(false);
     File4.setLayout(layout4);
     File4.add(lblPayment);
     File4.add(txtPayment);
     pane.add(File4);


                                                  // layout manager for layout 5 Buttons
     FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER, 15, 15);
     File5.setLayout(layout5);
     File5.add(Calculate);
     File5.add(Clear);
     File5.add(Exit);
     pane.add(File4);
     
     
                                                       // layout manager for layout 6
     FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER, 15, 15);
   File6.setLayout(layout6);
   JScrollPane scrollPane = new JScrollPane(area); // add the text area to
     File6.add(scrollPane);
     pane.add(File6);


//-------------------------------------------------------------
// DEVELOP 3 ITEM MENU BAR AND POPULATE IT
//-------------------------------------------------------------

     JMenuBar bar = new JMenuBar();
     File3.add(bar);
     JMenu menu = new JMenu("Select Fixed Rates and Terms");
     JMenuItem item = new JMenuItem("5.35% at 7 yrs");
     JMenuItem item1 = new JMenuItem("5.50% at 15 yrs");
     JMenuItem item2 = new JMenuItem("5.75% at 30 yrs");
     bar.add(menu);
     menu.add(item);
     menu.add(item1);
     menu.add(item2);
     pane.add(File7);


//-------------------------------------------------------------
// ADD ACTION LISTENERS
//-------------------------------------------------------------


     }    
//-------------------------------------------------------------
// CREATE THE GUI AND SHOW IT
//-------------------------------------------------------------          
           
    private static void createAndShowGUI()
      {
                                              // create and instantiate new frame, set basic properties
          JFrame frame = new JFrame("Simple Mortgage Calculator by McBride Financial");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setSize(600,600);
          frame.setVisible(true);
          }
         
//-------------------------------------------------------------
// MORTGAGE CALCULATIONS
//-------------------------------------------------------------

                                         // function to calculate the mortgage
          public void CalculateMortgage()
          {
         
          try          
                                        // declare and initialize variables
                                        // using virtual terminology - no idea how this works
                                        // looked at various Java sites
               {
               double LoanAmount = Double.valueOf(lblLoanAmount.getText()).doubleValue();
               double IntRate = Double.valueOf(lblIntRate.getText()).doubleValue();
               int Term = Integer.parseInt(lblTerm.getText());
               int Months = (Term * 12);
               double Payment = 0;
               double InterestPaid;
               String MonthlyPayment = new String();
               NumberFormat currency = NumberFormat.getCurrencyInstance();
               double I = (IntRate / 100.0 / 12.0);
               Payment = (LoanAmount * I) / (1 - Math.pow(1 / (1 + I), Months));
               lblPayment.setText(currency.format(Payment));

//-------------------------------------------------------------
// AMORTIZATION TABLE ERROR HANDLING
//-------------------------------------------------------------
}



               catch (NumberFormatException ex) {
                    }
               }

               protected void reset() {
               lblLoanAmount.setText(null);
               lblIntRate.setText(null);
               lblTerm.setText(null);
               lblPayment.setText(null);
               area.setText(null);


//-------------------------------------------------------------
// MAIN
//-------------------------------------------------------------
}

                                             // calls main and executes createAndShowGui
    public static void main(String[] args)
      {
         javax.swing.SwingUtilities.invokeLater(
                new Runnable()
               {
                   public void run()
                  {
                     createAndShowGUI();
                  }
               }); // END OF MAIN
      }
}
0
 

Author Comment

by:charliebaby
ID: 17976859
>>, SADProgram3Event class  class must be defined before use; I overlooked that sorry, fixed it, also added "}" at the end and commented the extra JButtons out, now six errors, am I close to fixxing this, I hope?

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


      public class SADProgram3 extends JPanel //implements ActionListener
      {
            SADProgram3Event HEARME = new SADProgram3Event(this);

//-------------------------------------------------------------
// DEFINE and DIMENSION VARIABLES AND BUTTON FUNCTIONS
//-------------------------------------------------------------

                                                                  // Buttons
            private JButton Calculate = new JButton("Calculate");
            private JButton Clear = new JButton("New Amount");
            private JButton Exit = new JButton("Exit");
                                                                  // text area to hold data;                  
            JTextArea area = new JTextArea(10, 20);
            
                                                                  // action listeners for buttons
            
            Calculate.addActionListener(HEARME);
            Clear.addActionListener(HEARME);
            Exit.addActionListener(HEARME);
            

//-------------------------------------------------------------
// BUILD THE DROP-DOWN MENU
//-------------------------------------------------------------
      
            JMenuBar menuBar;
            JMenuItem item;
            JToolBar toolBar;

//-------------------------------------------------------------
// BUILD THE LAYOUT FLOWS
//-------------------------------------------------------------
            
      public SADProgram3()
      {
                                                                  // trying to add pains
            
            GridLayout layout = new GridLayout(1, 1, 1, 1);
            Container pane = getContentPane();
            pane.setLayout(layout);
            
                                                                  // build the first layout panel and add label
            JPanel File1 = new JPanel();
            JLabel lblLoanAmount = new JLabel("Type the loan amount here",
            JLabel.CENTER);                         // center the label and set the text field to 10 char length
            JTextField txtLoanAmount = new JTextField(10);
            
            
                                                                  // build the second layout panel and add label
            JPanel File2 = new JPanel();
            JLabel lblIntRate = new JLabel("Type the interest rate here",
            JLabel.CENTER);                         // center the label and set the text field to 10 char length
            JTextField txtIntRate = new JTextField(10);
            
            
                                                                  // build the third layout panel and add label
            JPanel File3 = new JPanel();
            JLabel lblTerm = new JLabel("Type the loan term here",
            JLabel.CENTER);                         // center the label and set the text field to 10 char length
            JTextField txtTerm = new JTextField(10);
            

                                                                  // build the fourth layout panel and add label
            JPanel File4 = new JPanel();
            JLabel lblPayment = new JLabel("Your monthly payment",
            JLabel.CENTER);                         // center the label and set the text field to 10 char length
            JTextField txtPayment = new JTextField(10);
                        
            
//-------------------------------------------------------------
// ADD PAINS TO FRAMES
//-------------------------------------------------------------


                                                            // layout manager for layout 1 Loan Amount
      FlowLayout mgr = new FlowLayout(FlowLayout.CENTER, 15, 15);
      File1.setLayout(mgr);
      File1.add(lblLoanAmount);
      File1.add(txtLoanAmount);
      pane.add(File1);

                                                            // layout manager for layout 2 Rate
      FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER, 15, 15);
      File2.setLayout(layout2);
      File2.add(lblIntRate);
      File2.add(txtIntRate);
      pane.add(File2);
      
                                                            // layout manager for layout 3 Terms
      FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER, 15, 15);
      File3.setLayout(layout3);
      File3.add(lblTerm);
      File3.add(txtTerm);
      pane.add(File3);
      
                                                            // layout manager for layout 4 Payments
      FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER, 15, 15);
      lblPayment.setEditable(false);
      File4.setLayout(layout4);
      File4.add(lblPayment);
      File4.add(txtPayment);
      pane.add(File4);


                                                            // layout manager for layout 5 Buttons
      FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER, 15, 15);
      File5.setLayout(layout5);
      File5.add(Calculate);
      File5.add(Clear);
      File5.add(Exit);
      pane.add(File4);
      
      
                                                                  // layout manager for layout 6
      FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER, 15, 15);
   File6.setLayout(layout6);
   JScrollPane scrollPane = new JScrollPane(area); // add the text area to
      File6.add(scrollPane);
      pane.add(File6);


//-------------------------------------------------------------
// DEVELOP 3 ITEM MENU BAR AND POPULATE IT
//-------------------------------------------------------------

      JMenuBar bar = new JMenuBar();
      File3.add(bar);
      JMenu menu = new JMenu("Select Fixed Rates and Terms");
      JMenuItem item = new JMenuItem("5.35% at 7 yrs");
      JMenuItem item1 = new JMenuItem("5.50% at 15 yrs");
      JMenuItem item2 = new JMenuItem("5.75% at 30 yrs");
      bar.add(menu);
      menu.add(item);
      menu.add(item1);
      menu.add(item2);
      pane.add(File7);


//-------------------------------------------------------------
// ADD ACTION LISTENERS
//-------------------------------------------------------------


      }      
//-------------------------------------------------------------
// CREATE THE GUI AND SHOW IT
//-------------------------------------------------------------            
             
    private static void createAndShowGUI()
       {
                                                       // create and instantiate new frame, set basic properties
            JFrame frame = new JFrame("Simple Mortgage Calculator by McBride Financial");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setSize(600,600);
            frame.setVisible(true);
            }
            
//-------------------------------------------------------------
// MORTGAGE CALCULATIONS
//-------------------------------------------------------------

                                                 // function to calculate the mortgage
            public void CalculateMortgage()
            {
            
            try             
                                                // declare and initialize variables
                                                // using virtual terminology - no idea how this works
                                                // looked at various Java sites
                  {
                  double LoanAmount = Double.valueOf(virtual.LoanAmount.getText()).doubleValue();
                  double IntRate = Double.valueOf(virtual.IntRate.getText()).doubleValue();
                  int Term = Integer.parseInt(virtual.Term.getText());
                  int Months = (Term * 12);
                  double Payment = 0;
                  double InterestPaid;
                  String MonthlyPayment = new String();
                  NumberFormat currency = NumberFormat.getCurrencyInstance();
                  double I = (IntRate / 100.0 / 12.0);
                  Payment = (LoanAmount * I) / (1 - Math.pow(1 / (1 + I), Months));
                  virtual.MonthlyPayment.setText(currency.format(Payment));

//-------------------------------------------------------------
// AMORTIZATION TABLE ERROR HANDLING
//-------------------------------------------------------------


                  catch (NumberFormatException ex) {
                        }
                  }

                  protected void reset() {
                  virtual.LoanAmount.setText(null);
                  virtual.IntRate.setText(null);
                  virtual.Term.setText(null);
                  virtual.Payment.setText(null);
                  virtual.area.setText(null);


//-------------------------------------------------------------
// MAIN
//-------------------------------------------------------------

                                                      // calls main and executes createAndShowGui
    public static void main(String[] args)
      {
         javax.swing.SwingUtilities.invokeLater(
                new Runnable()
               {
                   public void run()
                  {
                     createAndShowGUI();
                  }
               }); // END OF MAIN
      }
      }      
      

0
 

Author Comment

by:charliebaby
ID: 17976892
Thank you That helped all the errors are telling me that can't find symbol, I fixed the class problem I thought, yet why cannot the programe recognize the class on such lines as>> Container pane = getContentPane();and>>     lblPayment.setEditable(false);
I must be missing something very fundumental
0
 
LVL 2

Expert Comment

by:avsrivastava
ID: 17976899
you managed to introduce new errors, some '}' are missing.

give the code I posted above a try. things that I have changed:
1)
The labels are used by more than one functions, so they can not be local to the constructor; declare them at the top of the class and
JLabel lblLoanAmount;
JLabel lblIntRate;
JLabel lblTerm;
JLabel lblPayment;
   
2)
removed the virtual keyword, it makes no sense why you used it at places.

3)
in CalculateMortgage() function
changed LoanAmount to lblLoanAmount (similiarly for others) where required.
you don't want to call setText on LoanAmount variable, rather on the corresponding label.

4)
declared JPanel File5, FIle6 and File7.
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 17976913
I'll leave this to avsrivastava :) as his / her answer has been comprehensive and I believe that he / she will be able to help you.

Good luck avsrivastava.

No point for me please.

David
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Accepted Solution

by:
avsrivastava earned 500 total points
ID: 17976931
For code to compile, I had to comment out the Event listener because the SADProgram3Event class is not available. The program does need some debugging though.
5)
use
getRootPane().getContentPane();
instead of getContentPane();

6)
there is no function called setEditable for JLabel, labels are not editable anyways, just comment that out.
lblPayment.setEditable(false);
0
 

Author Comment

by:charliebaby
ID: 17976951
I tell you what this a lot for a newbe lik me,( also I getting burnt out ) I want to help her , she hasen't had working code in five weeks now, so of course I feel bad for her, I am going to send her your improved code along with your recommendations, and let her make the corrections if she has time (I am sure she does her code  in between raising a family, and thats tricky) , before I close this question any more advice for her(and me), Thank you so much  suprapto45, and thank you David.  Charlie
0
 

Author Comment

by:charliebaby
ID: 17977001
Sorry I ment to thank you avsrivastava, I can't see straight right now sorry for that thank you again AVSRIVASTAVA!!!!
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 17977004
>>"before I close this question any more advice for her(and me)"
In my opinion, you are doing it in the right way and direction (for you) but not for her. I am not sure whether she will have a look at the codes and tries to understand it or not. However, I saw that you were struggling with the codes, you practiced, you tried and you know what, practice will make you better and better programmer. All of your questions are the same questions that I asked when I first learned Java.

So, please keep learning and try to move to J2EE which is the most popular technology today ;) but be careful, it is complex.

David
0
 

Author Comment

by:charliebaby
ID: 17977008
thanks again everybody, I LUV you all
0
 
LVL 2

Expert Comment

by:avsrivastava
ID: 17977182

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

     public class SADProgram3 extends JPanel //implements ActionListener
     {
     //     SADProgram3Event HEARME = new SADProgram3Event(this);

//-------------------------------------------------------------
// DEFINE and DIMENSION VARIABLES AND BUTTON FUNCTIONS
//-------------------------------------------------------------

                                                       // Buttons
//      JButton Calculate;
//      JButton Clear;
//      JButton Exit;
               
                                                       
                                                       
          private JButton Calculate = new JButton("Calculate");
          private JButton Clear = new JButton("New Amount");
          private JButton Exit = new JButton("Exit");
          JLabel lblLoanAmount;
          JLabel lblIntRate;
          JLabel lblTerm;
          JLabel lblPayment;
                                                 // text area to hold data;              
          JTextArea area = new JTextArea(10, 20);
         
                                                       // action listeners for buttons
         
                   

//-------------------------------------------------------------
// BUILD THE DROP-DOWN MENU
//-------------------------------------------------------------
     
          JMenuBar menuBar;
          JMenuItem item;
          JToolBar toolBar;

//-------------------------------------------------------------
// BUILD THE LAYOUT FLOWS
//-------------------------------------------------------------
         
     public SADProgram3()
     {
//      Calculate.addActionListener(HEARME);
//           Clear.addActionListener(HEARME);
//           Exit.addActionListener(HEARME);

                                                       // trying to add pains
         
          GridLayout layout = new GridLayout(1, 1, 1, 1);
          Container pane = getRootPane().getContentPane();
          pane.setLayout(layout);
         
                                                       // build the first layout panel and add label
          JPanel File1 = new JPanel();
          lblLoanAmount = new JLabel("Type the loan amount here",
          JLabel.CENTER);                     // center the label and set the text field to 10 char length
          JTextField txtLoanAmount = new JTextField(10);
         
         
                                                       // build the second layout panel and add label
          JPanel File2 = new JPanel();
          lblIntRate = new JLabel("Type the interest rate here",
          JLabel.CENTER);                     // center the label and set the text field to 10 char length
          JTextField txtIntRate = new JTextField(10);
         
         
                                                       // build the third layout panel and add label
          JPanel File3 = new JPanel();
          lblTerm = new JLabel("Type the loan term here",
          JLabel.CENTER);                     // center the label and set the text field to 10 char length
          JTextField txtTerm = new JTextField(10);
         

                                                       // build the fourth layout panel and add label
          JPanel File4 = new JPanel();
          lblPayment = new JLabel("Your monthly payment",
          JLabel.CENTER);                     // center the label and set the text field to 10 char length
          JTextField txtPayment = new JTextField(10);
                   
          JPanel File5 = new JPanel();
          JPanel File6 = new JPanel();
          JPanel File7 = new JPanel();
         
//-------------------------------------------------------------
// ADD PAINS TO FRAMES
//-------------------------------------------------------------


                                                  // layout manager for layout 1 Loan Amount
     FlowLayout mgr = new FlowLayout(FlowLayout.CENTER, 15, 15);
     File1.setLayout(mgr);
     File1.add(lblLoanAmount);
     File1.add(txtLoanAmount);
     pane.add(File1);

                                                  // layout manager for layout 2 Rate
     FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER, 15, 15);
     File2.setLayout(layout2);
     File2.add(lblIntRate);
     File2.add(txtIntRate);
     pane.add(File2);
     
                                                  // layout manager for layout 3 Terms
     FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER, 15, 15);
     File3.setLayout(layout3);
     File3.add(lblTerm);
     File3.add(txtTerm);
     pane.add(File3);
     
                                                  // layout manager for layout 4 Payments
     FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER, 15, 15);
     //lblPayment.setEditable(false);//<---labels are not editable anyways
     File4.setLayout(layout4);
     File4.add(lblPayment);
     File4.add(txtPayment);
     pane.add(File4);


                                                  // layout manager for layout 5 Buttons
     FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER, 15, 15);
     File5.setLayout(layout5);
     File5.add(Calculate);
     File5.add(Clear);
     File5.add(Exit);
     pane.add(File4);
     
     
                                                       // layout manager for layout 6
     FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER, 15, 15);
   File6.setLayout(layout6);
   JScrollPane scrollPane = new JScrollPane(area); // add the text area to
     File6.add(scrollPane);
     pane.add(File6);


//-------------------------------------------------------------
// DEVELOP 3 ITEM MENU BAR AND POPULATE IT
//-------------------------------------------------------------

     JMenuBar bar = new JMenuBar();
     File3.add(bar);
     JMenu menu = new JMenu("Select Fixed Rates and Terms");
     JMenuItem item = new JMenuItem("5.35% at 7 yrs");
     JMenuItem item1 = new JMenuItem("5.50% at 15 yrs");
     JMenuItem item2 = new JMenuItem("5.75% at 30 yrs");
     bar.add(menu);
     menu.add(item);
     menu.add(item1);
     menu.add(item2);
     pane.add(File7);


//-------------------------------------------------------------
// ADD ACTION LISTENERS
//-------------------------------------------------------------


     }    
//-------------------------------------------------------------
// CREATE THE GUI AND SHOW IT
//-------------------------------------------------------------          
           
    private static void createAndShowGUI()
      {
                                              // create and instantiate new frame, set basic properties
          JFrame frame = new JFrame("Simple Mortgage Calculator by McBride Financial");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setSize(600,600);
          frame.setVisible(true);
          }
         
//-------------------------------------------------------------
// MORTGAGE CALCULATIONS
//-------------------------------------------------------------

                                         // function to calculate the mortgage
          public void CalculateMortgage()
          {
         
          try          
                                        // declare and initialize variables
                                        // using virtual terminology - no idea how this works
                                        // looked at various Java sites
               {
               double LoanAmount = Double.valueOf(lblLoanAmount.getText()).doubleValue();
               double IntRate = Double.valueOf(lblIntRate.getText()).doubleValue();
               int Term = Integer.parseInt(lblTerm.getText());
               int Months = (Term * 12);
               double Payment = 0;
               double InterestPaid;
               String MonthlyPayment = new String();
               NumberFormat currency = NumberFormat.getCurrencyInstance();
               double I = (IntRate / 100.0 / 12.0);
               Payment = (LoanAmount * I) / (1 - Math.pow(1 / (1 + I), Months));
               lblPayment.setText(currency.format(Payment));

//-------------------------------------------------------------
// AMORTIZATION TABLE ERROR HANDLING
//-------------------------------------------------------------
}



               catch (NumberFormatException ex) {
                    }
               }

               protected void reset() {
               lblLoanAmount.setText(null);
               lblIntRate.setText(null);
               lblTerm.setText(null);
               lblPayment.setText(null);
               area.setText(null);


//-------------------------------------------------------------
// MAIN
//-------------------------------------------------------------
}

                                             // calls main and executes createAndShowGui
    public static void main(String[] args)
      {
          createAndShowGUI();
//        javax.swing.SwingUtilities.invokeLater(
//                 new Runnable()
//                {
//                    public void run()
//                   {
//                      createAndShowGUI();
//                   }
//                }); // END OF MAIN
      }
}
0
 

Author Comment

by:charliebaby
ID: 17980711
thanks again I will send this updated code to my friend...Charlie
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countPairs challenge 7 58
countHi2 challenge 7 44
wordappend challenge 8 84
unix in java example 9 39
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now