Applet help

From: atptour (atptour_at_insightbb.com)
Date: 04/04/04


Date: Sun, 04 Apr 2004 20:55:36 GMT

I have an applet that I am suppose to write for a java class. However, I am
stuck on one function of the applet. I need to keep a running total of
charges and display them in the status bar. I would appreciate any help
anyone can give. The applet works great as it is currently written, but the
totals do not reflect correctly. Please help.

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

public class A6_8R extends JApplet implements ActionListener {
JLabel promptLabel;
JTextField inputField;

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

promptLabel = new JLabel( "Enter number of hours: ");
inputField = new JTextField( 5 );
inputField.addActionListener( this );
container.add(promptLabel);
container.add(inputField);
}

public void actionPerformed( ActionEvent actionEvent)
{
double currentCharge = 0.00;

double hours = Double.parseDouble(actionEvent.getActionCommand() );
currentCharge = calculateCharges( hours );
showStatus( "Current charge: " + currentCharge + "; " + "Total Receipts: " +

calculateTotal( currentCharge ));
}

public double calculateCharges( double hours )
{
final double minimumCharge = 2.00;
final double maximumCharge = 10.00;
double finalCharge = 0.00;

if ( hours <= 3.0 )
{
finalCharge = minimumCharge;
}
else if ( hours > 3.0 && hours < 24.0)
{
finalCharge = minimumCharge + (0.50 * (hours - 3.0));
}
else if ( hours == 24.0)
{
finalCharge = maximumCharge;
}

return finalCharge;
}

public double calculateTotal ( double currentCharge )
{
double totalReceipts = 0.00;

totalReceipts += currentCharge;
return totalReceipts;
}

}



Relevant Pages

  • Applet Help
    ... I have an applet that I am suppose to write for a java class. ... currentCharge = calculateCharges; ... public double calculateCharges(double hours) ... finalCharge = minimumCharge; ...
    (comp.lang.java.help)
  • Applet Help
    ... I have an applet that I am suppose to write for a java class. ... currentCharge = calculateCharges; ... public double calculateCharges(double hours) ... finalCharge = minimumCharge; ...
    (comp.lang.java.programmer)
  • Re: Applet help
    ... > I have an applet that I am suppose to write for a java class. ... > public double calculateCharges(double hours) ... Every time you call the calculateTotal method, it resets the totalReceipts ...
    (comp.lang.java)