display multiple outputs in applet

Posted on 2003-03-29
Medium Priority
Last Modified: 2011-09-20
I'm sure this is simple - but I cannot seem to resolve it, or find the right answer.  I have a jave applet project to calculate a car loan.  I have it done and it is working EXCEPT....
Each calculation is correct and displays if I comment out the other 2.
   When I leave all 3 - just the last output shows...
I need all 3 output lines to show on my project... I've tried some different append syntax - but not finding the right ones...get nothing but errors.
I'd sure appreciate any recommendations ...thanks in advance!
Here's my code:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;  //import three

public class carLoanApplet2ND extends Applet implements ActionListener   //action is ActionListener - extends means to expect

  Label Title = new Label("Car Loan Calculator"); //title is the variable-name it anything
   Label costCarLabel = new Label ("Please enter the Price of the Car:"); //this is a prompt label
   TextField costCarField = new TextField(25); //this is a text box -25 characters
   Label downPaymentLabel = new Label ("Please enter the down payment:"); //this is another prompt
   TextField downPaymentField = new TextField(25); //text field to get data
   Label loanPeriodLabel = new Label ("Please enter the Loan Period in Years:"); //this is another prompt
   TextField loanPeriodField = new TextField(25); //text field to get data

   Button calcButton = new Button("Calculate Car Payment");  //button name label is in " "
   Label outputLabel = new Label ("Enter the data and then click the button");

   public void init()
      // Set Background color to cyan
      add(Title); // display title
      add(costCarLabel);  //display label

      calcButton.addActionListener(this);  //add button that states action performed - calls method

   public void actionPerformed(ActionEvent e)  //this is calculation method
    double costCar, downPayment, loanPeriod, loan, interest, payment;  //pass values
    //Converting input to values
    costCar =(double)Integer.parseInt(costCarField.getText()); //convert to value
    downPayment = (double)Integer.parseInt(downPaymentField.getText());
    loanPeriod = (double)Integer.parseInt(loanPeriodField.getText());

    //Calculation amount of loan
    loan = costCar - downPayment;

     //Calc interest
     if (loan < 5000)
        interest = .089;
        if (loan < 7500)
            interest = .079;
            if (loan < 8500)
                interest = .069;
                  if (loan < 10000)
                           interest = .059;
                                interest = .039;

    //Calculate payment
    payment = ((loan*interest) + loan) / (loanPeriod*12);

    //Output loan amount
    outputLabel.setText ("The Loan Amount =  $" + loan);

    //Output interest
    outputLabel.setText ("The Interest Rate is = " + interest);

    //Output payment
    outputLabel.setText ("The Loan Payment is =  $" + Math.round(payment));


Question by:vonb
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
LVL 15

Accepted Solution

ozymandias earned 200 total points
ID: 8232046
Why are you using a Label to show the output ?

If uou have to use a labelmthen why not use three position one under the other , and do :

outputLabel2.setText ("The Loan Amount =  $" + loan);
outputLabel2.setText ("The Interest Rate is = " + interest);
outputLabel3.setText ("The Loan Payment is =  $" + Math.round(payment));
LVL 92

Expert Comment

ID: 8232454
You are outputting results to the same label, so each overwrites the previous.
Either use 3 different labels as suggested by ozy, or use a TextArea with 3 lines and append each result on a new line.

Author Comment

ID: 8232510
Thanks -
The Label to show output was part of the assignment...
Thanks -You so much - I should have seen that, especially since only my last output was appearing....
thanks for helping me out!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 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