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...
public class SADProgram3 extends JPanel //implements ActionListener
{
SADProgram3Event HEARME = new SADProgram3Event(this);
//-------------------------------------------------------------
// DEFINE and DIMENSION VARIABLES AND BUTTON FUNCTIONS
//-------------------------------------------------------------
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
//-------------------------------------------------------------
// 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);
}
//-------------------------------------------------------------
// 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);
}
//-------------------------------------------------------------
// 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
}
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
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
//-------------------------------------------------------------
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
//-------------------------------------------------------------
// 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);
}
//-------------------------------------------------------------
// 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);
}
//-------------------------------------------------------------
// 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
Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.
>>, 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?
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);
//-------------------------------------------------------------
// BUILD THE DROP-DOWN MENU
//-------------------------------------------------------------
// 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);
}
//-------------------------------------------------------------
// 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);
}
//-------------------------------------------------------------
// 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
charliebabyAuthor Commented:
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
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.
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
charliebabyAuthor Commented:
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
charliebabyAuthor Commented:
Sorry I ment to thank you avsrivastava, I can't see straight right now sorry for that thank you again AVSRIVASTAVA!!!!
>>"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.
public class SADProgram3 extends JPanel //implements ActionListener
{
// SADProgram3Event HEARME = new SADProgram3Event(this);
//-------------------------------------------------------------
// DEFINE and DIMENSION VARIABLES AND BUTTON FUNCTIONS
//-------------------------------------------------------------
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
//-------------------------------------------------------------
// 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);
}
//-------------------------------------------------------------
// 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);
}
//-------------------------------------------------------------
// 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
charliebabyAuthor Commented:
thanks again I will send this updated code to my friend...Charlie
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.
One of a set of tools we're offering as a way of saying thank you for being a part of the community.
public static void main(String[] args)
{
javax.swing.SwingUtilities
new Runnable()
{
public void run()
{
createAndShowGUI();
}
}); // END OF MAIN
}
} // LOOK HERE - END OF CLASS