Solved

I can compile the code

Posted on 2006-10-26
3
227 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
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 …

726 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