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 3960872
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:54:26+00:00 2026-05-20T02:54:26+00:00

Running as a test application in Eclipse: ` //import all needed functionality import javax.swing.*;

  • 0

Running as a test application in Eclipse:

`    //import all needed functionality
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.*;
public class ScrofaniWk3 extends JApplet{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * @param args
     */
        // Declare variables and put code application logic here

        String userInput = null;
        JLabel loanAmountLabel = new JLabel("Loan Amount: ");
        JTextField loanAmount = new JTextField();
        double[] ratesList = {0.0535, 0.055, 0.0575};
        JLabel rateLabel=new JLabel("Interest Rate: ");
        JTextField rate=new JTextField();
        String[] yearsList = {"7","15","30"};
        JLabel yearsLabel=new JLabel("Years of Payment: ");
        JTextField years=new JTextField();
        JComboBox chooseYears = new JComboBox(yearsList);
        JLabel payLabel=new JLabel("Monthly Payment: ");
        JLabel payment=new JLabel();
        JButton calculate=new JButton("Calculate");
        JButton clear=new JButton("Clear");
        JButton quit=new JButton("Quit");
        JTextArea payments=new JTextArea();
        JScrollPane schedulePane=new JScrollPane(payments);
        Container mortCalc = getContentPane();


        public void init() {
        //This makes the chooseYears function
        chooseYears.setSelectedIndex(0);
        chooseYears.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent choose) {
        JComboBox cb = (JComboBox)choose.getSource();
        String termYear = (String)cb.getSelectedItem();
        years.setText(termYear);
        int index=0;
        switch (Integer.parseInt(termYear)) {
        case 7: index=0; break;
        case 15: index=1; break;
        case 30: index=2; break;
        }
        rate.setText(ratesList[index]+"");
        }
        });
        calculate.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {    
                    // Perform the calculation
                    double rateCalc=Double.parseDouble(rate.getText())/12;
                    double principalCalc=Double.parseDouble(loanAmount.getText());
                    double yearsCalc=Integer.parseInt(years.getText())*12;
                    double monthlyPayment=principalCalc*Math.pow(1+rateCalc,yearsCalc)*rateCalc/(Math.pow(1+rateCalc,yearsCalc)-1);

                    DecimalFormat df = new DecimalFormat("$###,###.##");
                    payment.setText(df.format(monthlyPayment));

                    // Perform extra calculations to show the loan amount after each subsequent payoff
                    double principal=principalCalc;
                    int month;
                    StringBuffer buffer=new StringBuffer();
                    buffer.append("Month\tAmount\tInterest\tBalance\n");
                    for (int f=0; f<yearsCalc; f++) {
                    month=f+1;
                    double interest=principal*rateCalc;
                    double balance=principal+interest-monthlyPayment;
                    buffer.append(month+"\t");
                    buffer.append(new String(df.format(principal))+"\t");
                    buffer.append(new String(df.format(interest))+"\t");
                    buffer.append(new String(df.format(balance))+"\n");
                    principal=balance;
                    }
                    payments.setText(buffer.toString());
                    } catch(Exception ex) {
                    System.out.println(ex);
                }
            }
        });
        clear.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                loanAmount.setText("");
                payment.setText("");
                payments.setText("");
            }
        });
        quit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(1);
            }
        });     
        //Config GUI
        JPanel panelMort=new JPanel();
        panelMort.setLayout(new GridLayout(5,2));
        panelMort.add(loanAmountLabel); panelMort.add(loanAmount);  
        panelMort.add(yearsLabel); panelMort.add(years);
        panelMort.add(new Label()); panelMort.add(chooseYears);
        panelMort.add(rateLabel); panelMort.add(rate);
        panelMort.add(payLabel); panelMort.add(payment);
        JPanel buttons=new JPanel();
        buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
        buttons.add(calculate); buttons.add(clear); buttons.add(quit);
        JPanel panelMort2=new JPanel();
        panelMort2.setLayout(new BoxLayout(panelMort2, BoxLayout.Y_AXIS));
        panelMort2.add(panelMort); panelMort2.add(buttons);
        mortCalc.add(BorderLayout.NORTH, panelMort);
        mortCalc.add(BorderLayout.CENTER, schedulePane);
    }
    public static void main(String[] args) {
        JApplet applet = new ScrofaniWk3();
        JFrame frameMort = new JFrame("ScrofaniWk3");
        frameMort.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frameMort.getContentPane().add(applet);
        frameMort.setSize(500,1000);

        frameMort.setResizable(true);
        frameMort.setVisible(true);

        applet.init();
        applet.start();

    }
}`
  • 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-05-20T02:54:26+00:00Added an answer on May 20, 2026 at 2:54 am

    You’ve got to simply check where you eventually add the buttons or the containers that hold the buttons.

    Check which JPanel you add your JButtons to — buttons
    Then check what you add buttons to — panelMort2
    Then check what you add panelMort2 to — nothing.

    This is nothing more than basic logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an automated test running application. In this part of the application,
I'm running some JUnit tests on my applications. Every test has a for loop
In my C# program, I have a thread that represents a running test, which
I have an automated test running on my program that generates some large MPG
Is there a way to make running junit test to stop after a test
We are using Team City and I noticed problem during running Watin test. Sometimes
I'm experiencing an issue on a test machine running Red Hat Linux (kernel version
Okay, so I'm running a small test webserver on my private network. I've got
When running tests in Ruby's unit::test framework, is there a really easy way to
I am running a Visual Studio Load Test using an Agent on one of

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.