Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:15:17+00:00 2026-06-01T15:15:17+00:00

I have written the code for AmortizationLoanSchedule in Swing but the look is not

  • 0

I have written the code for AmortizationLoanSchedule in Swing but the look is not good. How to adjust the sizes of the labels , text-field & button?

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

public class AmortizationLoanSchedule extends JApplet implements ActionListener {

    private JLabel LoanAmount = new JLabel("Loan Amount");
    private JLabel NumberOfYears = new JLabel("Number Of Years");
    private JLabel InterestRate = new JLabel("Interest Rate (Annual)");

    private JTextField jtfLoanAmount = new JTextField(10);
    private JTextField jtfNumberOfYears = new JTextField(10);
    private JTextField jtfInterestRate = new JTextField(10);

    // Calculate button is also needed
    private JButton jbtCalculate = new JButton("Amortize Loan");

    // ...and a text area where the results will be displayed
    private JTextArea jtaResults = new JTextArea();

    public void init() {
        try {
            // Panel p1 will hold the input
            JPanel p1 = new JPanel();
            p1.setLayout(new GridLayout(3, 3));
            p1.add(LoanAmount);
            p1.add(jtfLoanAmount);
            p1.add(NumberOfYears);
            p1.add(jtfNumberOfYears);
            p1.add(InterestRate);
            p1.add(jtfInterestRate);

            // Panel p2 will hold panel p1 and the calculate button
            JPanel p2 = new JPanel();
            p2.setLayout(new BorderLayout());
            p2
                    .setBorder(new TitledBorder(
                            "Enter loan amount, Number of years and annual interest rate"));
            p2.add(p1, BorderLayout.BEFORE_FIRST_LINE);
            p2.add(jbtCalculate, BorderLayout.AFTER_LAST_LINE);

            // Action listener for the button
            jbtCalculate.addActionListener(this);

            // Make the text area scrollable and uneditable
            JScrollPane scrollPane = new JScrollPane(jtaResults);
            jtaResults.setRows(12);
            jtaResults.setEditable(false);

            // Place the two panels to the applet
            getContentPane().add(p2, BorderLayout.NORTH);
            getContentPane().add(scrollPane, BorderLayout.SOUTH);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jbtCalculate)
            calculateLoan();
        else
            System.out.println("you will never see this text!");

    }

    public void calculateLoan() {
        if ((jtfNumberOfYears.getText().equals(""))
                || (jtfLoanAmount.getText().equals(""))
                || (jtfInterestRate.getText().equals(""))) {
            JOptionPane.showMessageDialog(null, "All fields are mandatory",
                    null, 1);
        } else {
            int numberOfYears = Integer.parseInt(jtfNumberOfYears.getText());
            double loanAmount = Double.parseDouble(jtfLoanAmount.getText());
            double annualInterestRate = (Double.parseDouble(jtfInterestRate
                    .getText())) / 100;

            double monthlyInterestRate = annualInterestRate / 12;
            double numberOfMonths = numberOfYears * 12;
            double monthlyPayment = loanAmount
                    * (monthlyInterestRate / (1 - Math.pow(
                            1 + monthlyInterestRate, -numberOfMonths)));
            double totalPayment = monthlyPayment * numberOfMonths;
            double balance = loanAmount;
            double interest;
            double principal;

            jtaResults.append("Payment#\t" + "Interest\t" + "Principal\t"
                    + "Balance\n\n");

            for (int i = 0; i < numberOfYears * 12; i++) {
                interest = (int) (monthlyInterestRate * balance * 100) / 100.0;
                principal = (int) ((monthlyPayment - interest) * 100) / 100.0;
                balance = (int) ((balance - principal) * 100) / 100.0;

                jtaResults.append(i + 1 + "\t" + interest + "\t" + principal
                        + "\t" + balance + "\n");
            }

            jtaResults.append("\n\nMonthly Payment: $"
                    + (int) (monthlyPayment * 100) / 100.0 + "\n");
            jtaResults.append("Total Payment: $" + (int) (totalPayment * 100)
                    / 100.0 + "\n\n");
        }
    }
}

AmortizationLoanSchedule

Update

This is what is required.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:15:18+00:00Added an answer on June 1, 2026 at 3:15 pm

    AmortizationLayout

    import java.awt.*;
    import javax.swing.*;
    
    import javax.swing.border.TitledBorder;
    
    class AmortizationLayout {
    
        AmortizationLayout() {
            JPanel gui = new JPanel(new BorderLayout(2,2));
    
            JPanel labelFields = new JPanel(new BorderLayout(2,2));
            labelFields.setBorder(new TitledBorder("BorderLayout"));
    
            JPanel labels = new JPanel(new GridLayout(0,1,1,1));
            labels.setBorder(new TitledBorder("GridLayout"));
            JPanel fields = new JPanel(new GridLayout(0,1,1,1));
            fields.setBorder(new TitledBorder("GridLayout"));
    
            for (int ii=1; ii<4; ii++) {
                labels.add(new JLabel("Label " + ii));
                // if these were of different size, it would be necessary to
                // constrain them using another panel
                fields.add(new JTextField(10));
            }
    
            labelFields.add(labels, BorderLayout.CENTER);
            labelFields.add(fields, BorderLayout.EAST);
    
            JPanel guiCenter = new JPanel(new BorderLayout(2,2));
            guiCenter.setBorder(new TitledBorder("BorderLayout"));
            JPanel buttonConstrain = new JPanel(new FlowLayout(FlowLayout.CENTER));
            buttonConstrain.setBorder(new TitledBorder("FlowLayout"));
            buttonConstrain.add( new JButton("Click Me") );
            guiCenter.add( buttonConstrain, BorderLayout.NORTH );
    
            guiCenter.add(new JScrollPane(new JTextArea(5,30)));
    
            gui.add(labelFields, BorderLayout.NORTH);
            gui.add(guiCenter, BorderLayout.CENTER);
    
            JOptionPane.showMessageDialog(null, gui);
        }
    
        public static void main(String[] args) throws Exception {
            //Create the GUI on the event dispatching thread
            SwingUtilities.invokeLater(new Runnable(){
                @Override
                public void run() {
                    new AmortizationLayout();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written code to perform click event on JMenuItem but that is not
I have written code in -(void)applicationWillEnterForeground:(UIApplication *)application , but my application is not detecting
I have written code for many patterns but unable to write for this..... not
I have written code for javascript but it is not called any how. I
I have written some code to look at properties using reflection. I have retrieved
I have written code below.but it will print this exception and i really don't
I have written code ORM::factory('cds')->find_all(1, 2); It is returning all row . But according
I have written code to generate thumbnails from pdf files & save them as
I have written code to insert an Image in SQL server but it throws
I have written code that opens 16 figures at once. Currently, they all open

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.