Solved

I can compile the code

Posted on 2006-10-26
3
223 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
3 Comments
 
LVL 9

Accepted Solution

by:
shinobun earned 250 total points
Comment Utility
         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
Comment Utility
> Container contentPane = getContentPane();
JPanel contentPane = (JPanel) getContentPane();
0
 

Author Comment

by:charliebaby
Comment Utility
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

IT, Stop Being Called Into Every Meeting

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!

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 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

11 Experts available now in Live!

Get 1:1 Help Now