?
Solved

I can compile the code

Posted on 2006-10-26
3
Medium Priority
?
229 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 1000 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 1000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

770 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