Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

I need help with this applet

jrclarejrclare Member Posts: 2
The question is in the comments:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ParkGarage extends JApplet implements ActionListener
{
final double MIN_FEE = 2.0,
HOUR_FEE = 0.5,
MIN_TIME = 3.0,
MAX_FEE = 10.0;
double totalFee = 0.0;

JLabel lblCName, lblCTime;
JTextField txtCName, txtCTime;

public void init()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());

lblCName = new JLabel("Enter customers name: ");
lblCTime = new JLabel("Enter Hours Parked: ");
txtCName = new JTextField(10);
// how do I get the value of txtCName into a String so I can output it
// in showStatus below?
txtCTime = new JTextField(2);
txtCTime.addActionListener(this);
c.add(lblCName);
c.add(txtCName);
c.add(lblCTime);
c.add(txtCTime);
}

public void actionPerformed(ActionEvent e)
{
double time = Double.parseDouble(e.getActionCommand());
double fee = calculateCharges(time);
totalFee += fee;
showStatus("Customer " + " Owes " + fee + " Totalfees for day are " + totalFee);

// would like to add the the result of the string from txtCName above in showStatus
// example.. showStatus("customer" + txtCName + "Owes" + fee + etc...............)
}

public double calculateCharges(double time)
{
double fee = 0.0;
if(time <= MIN_TIME)
fee = MIN_FEE;
else
{
fee = time - MIN_TIME;
fee = MIN_FEE + (fee * HOUR_FEE);
}
if(fee > MAX_FEE)
fee = MAX_FEE;
return fee;
}
}



Comments

  • beancounterbeancounter Member Posts: 88
    Hi,

    I think this is what you need...

    : // how do I get the value of txtCName into a String so I can output it
    : // in showStatus below?

    [code] String whatever = txtCName.getText();[/code]



    : // would like to add the the result of the string from txtCName above in showStatus
    : // example.. showStatus("customer" + txtCName + "Owes" + fee + etc...............)
    : }

    [code] showStatus("customer" + txtCName.getText() + "Owes"+ fee +etc);[/code]



  • jrclarejrclare Member Posts: 2
    Thanks. That did the trick.


    : Hi,
    :
    : I think this is what you need...
    :
    : : // how do I get the value of txtCName into a String so I can output it
    : : // in showStatus below?
    :
    : [code] String whatever = txtCName.getText();[/code]
    :
    :
    :
    : : // would like to add the the result of the string from txtCName above in showStatus
    : : // example.. showStatus("customer" + txtCName + "Owes" + fee + etc...............)
    : : }
    :
    : [code] showStatus("customer" + txtCName.getText() + "Owes"+ fee +etc);[/code]
    :
    :
    :
    :

  • Andre YoungAndre Young USAMember Posts: 0

    ______ < http://forcoder.org /> free video tutorials and ebooks about || Perl R MATLAB Ruby Visual Basic Java Scratch C Swift C++ Visual Basic .NET Delphi PHP C# Python PL/SQL Assembly Objective-C Go JavaScript Julia ABAP SAS Logo Ada Awk Crystal Lua F# Scheme Rust Hack Kotlin Erlang D Scala Prolog Alice Apex Transact-SQL Bash Dart LabVIEW ML Lisp FoxPro COBOL Clojure VBScript Fortran || ________

Sign In or Register to comment.