Solved

I can compile the code

Posted on 2006-10-26
3
228 Views
Last Modified: 2013-11-23
I can compile the code but it won't run, I think it doesn't know that there is a GUI, What bit of code am I missing, it must be a hair off somewhere please offer some advice to me, Thank you, Charlie


import java.io.*;
import javax.swing.*;
import java.math.*;
import java.applet.*;
import java.awt.*;
 
public class MortgageCalculatorXXX extends JApplet
{
 
//declare and construct variables
      double mortgagePayment;
      double term = 0.0;
      double loanAmount = 0.0;
      double interestRate = 0.0;
 
      String loans[] = {"7 year at 5.35%", "15 year at 5.5%", "30 year at 5.75%"};
 
  public void init()
     {
 
      //Execute a job on the event-dispatching thread:
      //creating this applet's GUI.
      try
      {
      javax.swing.SwingUtilities.invokeAndWait(new Runnable()
          {
      public void run()
              {
      createGUI();
              }
          });
        }
      catch (Exception e)
      {
      System.err.println("createGUI didn't successfully complete");
        }
           }
      private void createGUI()
   {
      JComboBox combo;    // add this line
 
          //Create a panel and add components to it.
          JPanel contentPane = new JPanel(new BorderLayout());
 
          //Make it the content pane.
          contentPane.setOpaque(true);
 
          // Create a combobox
          combo = new JComboBox();
          combo.setBounds( 20, 35, 260, 20 );
          contentPane.add( combo );
 
          JFrame frame;
          JPanel panel;
          JLabel prinLbl, aprLbl, termLbl, pymtLbl;
          JTextField prinTf, aprTf, termTf, pymtTf;
          JButton calcBtn;
 
          contentPane.setLayout(new GridLayout(5,2));
          prinLbl = new JLabel ("loanAmount?");
          aprLbl = new JLabel ("interestRate?");
          termLbl = new JLabel ("term?");
          pymtLbl = new JLabel ("MortgagePayment");
 
          frame = new JFrame("Mortgage Calculator");
          panel = new JPanel();
          JLabel label = new JLabel("You are successfully running a Swing applet!");
          label.setHorizontalAlignment(JLabel.CENTER);
          label.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.black));
 
 
           //calculations
           mortgagePayment = (loanAmount)*
           ((interestRate/1200)/(1-Math.pow((1+(interestRate/1200)),-(term))));
       }
    }
0
Comment
Question by:charliebaby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
shinobun earned 250 total points
ID: 17817150
         JPanel contentPane = new JPanel(new BorderLayout());

Should be:

        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

Or, do a getContentPane().add(contentPane);

Otherwise, all the stuff you did will just get garbage collected.  :)
0
 
LVL 14

Assisted Solution

by:hoomanv
hoomanv earned 250 total points
ID: 17817833
> Container contentPane = getContentPane();
JPanel contentPane = (JPanel) getContentPane();
0
 

Author Comment

by:charliebaby
ID: 17821853
Thanks to the both of you I realized just now that i cant use an  JApplett method anyway, thanks for the trouble... will split the points.
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

691 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