I need help with this applet

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

  • 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]



  • 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]
    :
    :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

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

Categories