Results 1 to 11 of 11

Thread: Debug Please

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432

    Angry 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.

  2. #2
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    1- Use [c0de] [/c0de]

    2-Write the error please.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    its not outputing the results in the label

  4. #4
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Thats because you didn't add the action listener to the button
    Add this to your init
    btnCalculate.addActionListener(this);

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    OMG DAHHHH thanks :-) little brain fart THANKS

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432

    Question

    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);
    
      }
    }

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    *BUMP*

  8. #8
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    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.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  10. #10
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    They do. Well, guess you do learn something new everyday. How much memory does a float take?

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width