|
-
Sep 20th, 2002, 11:34 PM
#1
Thread Starter
Hyperactive Member
Debug Please
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
public class Charge extends Applet implements ActionListener
{
Label lblPackage_ID = new Label("Package ID# ");
Label lblPackage_Pounds = new Label("Package Pounds");
Label lblPackage_Ounces = new Label("Package Ounces");
Label lblPackage_Pounds_Total = new Label(" ");
Label lblPackage_Ounces_Total = new Label(" ");
Label lblError = new Label("Error");
TextField txtPackage_ID = new TextField("154496P");
TextField txtPounds = new TextField("0");
TextField txtOunces = new TextField("5");
Button btnCalculate = new Button("Calculate");
//Declair Var's
final float fltSCharge = 0.12f;
final float fltCharge = 1.92f;
float fltPounds_Calculation;
float fltOunces_Calculation;
String strPounds;
String strOunces;
public void init()
{
setBackground(Color.darkGray);
add(lblPackage_ID);
add(txtPackage_ID);
add(lblPackage_Pounds);
add(txtPounds);
add(lblPackage_Ounces);
add(txtOunces);
add(btnCalculate);
lblError.setForeground(Color.red);
add(lblError);
add(lblPackage_Pounds_Total);
add(lblPackage_Ounces_Total);
}
public void actionPerformed(ActionEvent p1)
{
float fltPounds = Float.valueOf(txtPounds.getText()).floatValue();
float fltOunces = Float.valueOf(txtOunces.getText()).floatValue();
NumberFormat fmtDecimal = NumberFormat.getInstance();
fmtDecimal.setMaximumFractionDigits(2);
fmtDecimal.setMinimumFractionDigits(2);
NumberFormat fmtCurrency = NumberFormat.getCurrencyInstance();
if (fltPounds > 0)
{
fltPounds_Calculation = fltPounds * fltCharge;
}
if (fltOunces > 0)
{
fltOunces_Calculation = fltOunces * fltSCharge;
}
strPounds = String.valueOf(fltPounds_Calculation);
strOunces = String.valueOf(fltOunces_Calculation);
lblPackage_Pounds_Total.setText(strPounds);
lblPackage_Ounces_Total.setText(strOunces);
}
}
Its not displaying the Result in the Labels?
Last edited by 308holes; Sep 21st, 2002 at 08:50 PM.
-
Sep 21st, 2002, 04:03 PM
#2
Ya ya Baby!!!Me is Back
1- Use [c0de] [/c0de]
2-Write the error please.
-
Sep 21st, 2002, 08:51 PM
#3
Thread Starter
Hyperactive Member
its not outputing the results in the label
-
Sep 22nd, 2002, 12:59 PM
#4
Hyperactive Member
Thats because you didn't add the action listener to the button
Add this to your init
btnCalculate.addActionListener(this);
-
Sep 22nd, 2002, 03:49 PM
#5
Thread Starter
Hyperactive Member
OMG DAHHHH thanks :-) little brain fart THANKS
-
Sep 22nd, 2002, 04:02 PM
#6
Thread Starter
Hyperactive Member
ok now im haveing proplems with the calculations....
it works fine on the ounces up till i use 3??
it should be 36 not 35 and it it off bye 1 from then one ?????
Code:
/*
Programmer : Chad Eckles
Date : 9/14/02
Class : Charge
Folder : A:\ShippingCharge\ShippingCharge.jpx
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
public class Charge extends Applet implements ActionListener
{
Label lblPackage_ID = new Label("Package ID# ");
Label lblPackage_Pounds = new Label("Package Pounds");
Label lblPackage_Ounces = new Label("Package Ounces");
Label lblPackage_Pounds_Total = new Label(" ");
Label lblPackage_Ounces_Total = new Label(" ");
Label lblError = new Label("Error");
TextField txtPackage_ID = new TextField("154496P");
TextField txtPounds = new TextField("0");
TextField txtOunces = new TextField("5");
Button btnCalculate = new Button("Calculate");
//Declair Var's
final float fltSCharge = .12f;
final float fltCharge = 1.92f;
float fltPounds_Calculation;
float fltOunces_Calculation;
String strPounds;
String strOunces;
public void init()
{
setBackground(Color.darkGray);
add(lblPackage_ID);
add(txtPackage_ID);
add(lblPackage_Pounds);
add(txtPounds);
add(lblPackage_Ounces);
add(txtOunces);
btnCalculate.addActionListener(this);
add(btnCalculate);
lblError.setForeground(Color.red);
add(lblError);
add(lblPackage_Pounds_Total);
add(lblPackage_Ounces_Total);
}
public void actionPerformed(ActionEvent p1)
{
float fltPounds = Float.valueOf(txtPounds.getText()).floatValue();
float fltOunces = Float.valueOf(txtOunces.getText()).floatValue();
NumberFormat fmtDecimal = NumberFormat.getInstance();
fmtDecimal.setMaximumFractionDigits(2);
fmtDecimal.setMinimumFractionDigits(2);
NumberFormat fmtCurrency = NumberFormat.getCurrencyInstance();
if (fltPounds > 0)
{
fltPounds_Calculation = fltPounds * fltCharge;
}
if (fltOunces > 0)
{
fltOunces_Calculation = fltOunces * fltSCharge;
}
strPounds = String.valueOf(fltPounds_Calculation);
strOunces = String.valueOf(fltOunces_Calculation);
lblPackage_Pounds_Total.setText(strPounds);
lblPackage_Ounces_Total.setText(strOunces);
}
}
-
Sep 22nd, 2002, 11:48 PM
#7
Thread Starter
Hyperactive Member
-
Sep 23rd, 2002, 05:49 PM
#8
Hyperactive Member
Not quite sure why you're using floats, but the problem comes there. Just use doubles. Can't really see that you'll go over that limit. Seems you're just wasting memory with floats.
-
Oct 16th, 2002, 11:27 AM
#9
Uh, floats use less memory than doubles...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 16th, 2002, 01:55 PM
#10
Hyperactive Member
They do. Well, guess you do learn something new everyday. How much memory does a float take?
-
Oct 16th, 2002, 03:29 PM
#11
4 bytes. double uses 8 bytes. That's what double means: double precision, thus double memory usage.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|