Current location: Hot Scripts Forums » Programming Languages » Everything Java » Help with Applet


Help with Applet

Reply
  #1 (permalink)  
Old 04-03-04, 09:24 PM
csmatheng csmatheng is offline
New Member
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Help with Applet

I have a very simple applet to write and I have most of it done. However, I am confused about one easy function that the program is suppose to perform. I would appreciate any help. The problem I am stuck on is how to calculate the running total, hence totalReceipts. I know it is a position thing and normally would use a loop to do this. However, with an applet, I am a little confused. Here is the code I have:

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 totalReceipts = 0.00;

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

totalReceipts );
}

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;
}
}
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript menu covered by java applet shaisachs JavaScript 7 12-28-04 11:38 PM
Java applet Bobo Everything Java 1 06-14-04 07:42 AM
Applet BackGround Muslim_Girl Everything Java 1 02-06-04 10:41 AM
ASP in Java applet buttons geneane Everything Java 2 10-09-03 03:52 AM
Slow Animation on top of Java Applet mark4man Everything Java 5 09-07-03 09:02 AM


All times are GMT -5. The time now is 06:03 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.