Solved

I can compile the code

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 84
Base1 Encode/Decode 3 77
What are programming codes and how do they work? 7 93
iSeries email authority 6 57
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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