Mortgage Calculator GUI

Posted on 2005-05-13
Last Modified: 2008-01-09
Good Evening all. I am am getting the following error when I try to compile my program: "Week2_GUILayout is not abstract and does not override abstract method minimumLayoutSize (java.awt.Container) in java.awt.LayoutManager". Any ideas on how I can fix this? This is the first GUI I have done.  Also, is it necessary to have a container, or can I use a Flow Layout? Would that effect the outcome of my program? Other that a Container for the layout, what would work better?

import javax. swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.applet.Applet;

public class Week2_GUI extends JApplet{
      JLabel label_a;
      JLabel label_b;
      JLabel label_c;
      JTextField textfield_a;
      JTextField textfield_b;
      JTextField textfield_c;
      JButton calculate;
      JLabel label_d;
      JButton Start_Again;
      JLabel label_e;
      public static void main(String args[]){
            JFrame f = new JFrame("Mortgage Payment Calculator");
            Week2_GUI calc = new Week2_GUI();
      public void init(){
Week2_GUILayout customLayout = new Week2_GUILayout();

      Container con = getContentPane();

      label_a = new JLabel("Amount of Loan");

      label_b = new JLabel("Interest Rate");

      label_c = new JLabel("Term of Loan");

      textfield_a = new JTextField("");

      textfield_b = new JTextField("");
      textfield_c = new JTextField("");
      JButton calculate = new JButton("Calculate");
      label_d = new JLabel("Payment Amount");
      JButton Start_Again = new JButton("Start Again");
      label_e = new JLabel("$");
      calculate.addActionListener(new ActionListener(){
            public void actionPerformed (ActionEvent h)
                  double amount = Double.parseDouble(textfield_a.getText());
                  double interest = Double.parseDouble(textfield_b.getText());
                  interest = interest/100;
                  double term = Double.parseDouble(textfield_c.getText());
                  double payment=Math.round((amount*interest/12*Math.pow(interest/12+1,term*12))/(Math.pow(interest/12+1,term*12)-1));
      Start_Again.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent h)


class Week2_GUILayout implements LayoutManager{
      public Week2_GUILayout(){
public void addLayoutComponent(String name, Component comp){

public void removeLayoutComponent(Component comp){

public Dimension preferredLayoutSize(Container parent){
      Dimension t = new Dimension(0,0);
      Insets i = parent.getInsets();
      t.width = 539 + i.left + i.right;
      t.height = 394 + + i.bottom;
      return t;

public void layoutContainer(Container parent){
      Insets i = parent.getInsets();
      Component w;
      w = parent.getComponent(0);
        if (w.isVisible()) {w.setBounds(i.left+8,,96,24);}
        w = parent.getComponent(1);
        if (w.isVisible()) {w.setBounds(i.left+8,,96,24);}
        w = parent.getComponent(2);
        if (w.isVisible()) {w.setBounds(i.left+8,,96,24);}
        w = parent.getComponent(3);
        if (w.isVisible()) {w.setBounds(i.left+112,,112,24);}
        w = parent.getComponent(4);
        if (w.isVisible()) {w.setBounds(i.left+112,,112,24);}
        w = parent.getComponent(5);
        if (w.isVisible()) {w.setBounds(i.left+112,,112,24);}
        w = parent.getComponent(6);
        if (w.isVisible()) {w.setBounds(i.left+112,,112,24);}
        w = parent.getComponent(7);
        if (w.isVisible()) {w.setBounds(i.left+8,,96,24);}
        w = parent.getComponent(8);
        if (w.isVisible()) {w.setBounds(i.left+112,,112,24);}
        w = parent.getComponent(9);
        if (w.isVisible()) {w.setBounds(i.left+112,,72,24);}

Question by:magmaya
    LVL 92

    Expert Comment


    Add a method minimumLayoutSize(java.awt.Container) to the Week2_GUILayout class

    LVL 92

    Expert Comment

    fillowing should do:

    public Dimension minimumLayoutSize(Container container)
       return preferredLayoutSize(container);

    Author Comment

    Thank you! My program compiled well. For my mortgage payment formula. I don't like rounding up the payment. I was looking at, and I am trying to figure out how to have the full payment amount show... (w/ 2 decimal places) ex: $1113.67.  Any suggestions?

    Author Comment

    Also, would I change my GUI to use FlowLayout instead of hard coding the positions in the container?
    LVL 92

    Accepted Solution

    Use a NumberFormat

    NumberFormat nf = NumberFormat.getCurrencyInstance();

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    734 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

    23 Experts available now in Live!

    Get 1:1 Help Now