Results 1 to 4 of 4
  1. #1
    pablo2002 is offline Member
    Join Date
    Sep 2010
    Posts
    6
    Rep Power
    0

    Default Mortgage Calculator

    I compile the java code and no problem. Then run java application and no problem. I then try to convert to Java Applet and i receive errors.

    C:\AIU\MIS\Object-Oriented\Projects\Wahlen5IPSolution.java:95: cannot find symbol
    symbol : method setDefaultCloseOperation(int)
    location: class Wahlen5IPSolution
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ^
    C:\AIU\MIS\Object-Oriented\Projects\Wahlen5IPSolution.java:134: cannot find symbol
    symbol : method pack()
    location: class Wahlen5IPSolution
    pack();
    ^
    2 errors

    Tool completed with exit code 1


    Code is below


    //Import all required Packages
    import javax.swing.*;
    import java.awt.*;
    import java.text.*;
    import java.awt.event.*;


    public class Wahlen5IPSolution extends JApplet implements ActionListener {


    double userAmount;
    double userInterest;
    double userTerm;


    int month = 0;
    double remainBalance = 0;
    double interestPayment = 0;
    double principalPaid = 0;


    JPanel row1;
    JLabel lblAmount;
    JTextField txtAmount;
    JLabel lblInterest;
    JTextField txtInterest;
    JLabel lblTerm;
    JTextField txtTerm;
    JLabel lblPayment;
    JTextField txtPayment;

    JPanel row2;
    JLabel lblHeader;
    JTextArea txtResults;
    JScrollPane textPane;


    JPanel row3;
    JButton calculateButton;
    JButton clearButton;
    JButton exitButton;


    public void init()
    {

    //Instantiate GUI Components
    //super("Mortgage Calculator");


    // row1
    row1 = new JPanel();

    lblAmount = new JLabel(" Mortgage: $", JLabel.LEFT);
    txtAmount = new JTextField(10);


    lblInterest = new JLabel("Interest %", JLabel.LEFT);
    txtInterest = new JTextField(6);

    lblTerm = new JLabel("Term in Years", JLabel.LEFT);
    txtTerm = new JTextField(6);

    lblPayment = new JLabel("Payment:");
    txtPayment = new JTextField(10);



    // row2
    row2 = new JPanel(new BorderLayout());

    String pad = " ";
    lblHeader = new JLabel("Payment #"+pad+"Payment Amount:"+pad+"Interest Paid:"+pad+"New Balance:");

    txtResults = new JTextArea(10, 53);
    textPane = new JScrollPane(txtResults);



    //row 3
    row3 = new JPanel(new GridLayout(1,3,75,1));

    calculateButton = new JButton("Calculate");
    clearButton = new JButton("Clear");
    exitButton = new JButton("Exit");



    //Build GUI

    setSize(600, 250);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    row1.add(lblAmount);
    row1.add(txtAmount);

    row1.add(lblInterest);
    row1.add(txtInterest);

    row1.add(lblTerm);
    row1.add(txtTerm);

    row1.add(lblPayment);
    row1.add(txtPayment);

    txtPayment.setEditable(false);



    textPane.setPreferredSize(new Dimension(610,200));
    row2.add(lblHeader,BorderLayout.NORTH);
    row2.add(textPane,BorderLayout.CENTER);



    //Create Calculate button and add listener
    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();
    }





    //Define actions performed for buttons
    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource() == calculateButton)
    {


    double balance = 0;
    double monthPayment=0;



    userAmount = Double.parseDouble(txtAmount.getText());

    userInterest = Double.parseDouble(txtInterest.getText());

    userTerm = Double.parseDouble(txtTerm.getText());



    //formats answer in currency format then to string format for display
    NumberFormat fmt = NumberFormat.getCurrencyInstance();
    monthPayment = CalculateMonthlyPayment();
    String payment = fmt.format(monthPayment);
    txtPayment.setText(" "+payment);



    balance = userAmount;
    month = (int)userTerm * 12;

    for(int index = 1; index <= month ; index++)
    {
    interestPayment = balance * (userInterest * .01/12);
    principalPaid = monthPayment - interestPayment;
    remainBalance = balance - principalPaid;


    txtResults.append(" " + index + "\t\t "+ fmt.format(balance) + "\t\t"
    + fmt.format(interestPayment) + "\t\t" + fmt.format(remainBalance) + "\n");

    balance = remainBalance;
    }


    }

    else if (e.getSource() == clearButton)
    {
    txtAmount.setText(null);
    txtPayment.setText(null);
    txtResults.setText(null);
    }

    else if (e.getSource() == exitButton)
    {
    System.exit(0);
    }
    }


    //Mortgage Payment Calculations
    double CalculateMonthlyPayment()
    {

    return (userAmount * ((1 + (userInterest*.01)/12)-1) / (1-(Math.pow((1+(userInterest*.01)/12),-(userTerm*12)))));

    }




    public static void main(String[] args)
    {
    new Wahlen5IPSolution().setVisible(true);
    }

    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    Wahlen5IPSolution.java:95: cannot find symbol
    symbol : method setDefaultCloseOperation(int)
    location: class Wahlen5IPSolution
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Where is the method referred to in the error message defined? The compiler can't find it.

    Wahlen5IPSolution.java:134: cannot find symbol
    symbol : method pack()
    location: class Wahlen5IPSolution
    pack();
    Same problem. Where is the pack method defined?

    Your Wahlen5IPSolution class is now extending a different class with different methods.

  3. #3
    pablo2002 is offline Member
    Join Date
    Sep 2010
    Posts
    6
    Rep Power
    0

    Default

    Thanks, You were correct. I just fixed. My last question is thus; I used Textpad linked to my java compiler. I have compiled correctly. Created a class file and finally have a html file. When I use texpad and launch the html the applet works perfectly. When I launchthe htmil file, my browser give me a a blank page. What is the secret for just clicking on the html file so it launch the java applet. Bioth files are in the same directory.

    <HTML>

    <HEAD>

    <Title>Wahlen5IPSolutionApplet</Title>

    </HEAD>

    <BODY>

    Here is the output of my program:
    <APPLET CODE="Wahlen5IPSolution.class" WIDTH="150" HEIGHT="25">

    </APPLET>

    </BODY>

    </HTML>

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    I don't see any errors in the html. One change you could make is to remove the .class in the end of the code= attribute. Some browsers have a problem with that.
    Look in the browser's java console to see if there are any error messages there.

Similar Threads

  1. need help with my calculator
    By semoche in forum AWT / Swing
    Replies: 6
    Last Post: 12-04-2009, 10:16 PM
  2. Calculator
    By water in forum AWT / Swing
    Replies: 4
    Last Post: 09-23-2009, 06:00 AM
  3. help with calculator
    By kalibballer in forum New To Java
    Replies: 8
    Last Post: 04-01-2009, 12:57 PM
  4. mortgage calculator help
    By kalibballer in forum New To Java
    Replies: 1
    Last Post: 03-26-2009, 11:35 AM
  5. Calculator help.
    By madkidd02 in forum New To Java
    Replies: 2
    Last Post: 10-25-2008, 07:42 AM

Posting Permissions

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