Results 1 to 5 of 5
  1. #1
    boybackup is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default pls. help on my unknown error

    my brain is bleeding bcoz of this simple program.. pls. help
    i just need to add the money to the balance but the when i always deposit.. it displays the new number, not adding.. i dunno why.. please help
    masters....


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

    public class MenuTable extends JFrame
    {
    private JLabel depL, widL;
    private JTextField depTxt, widTxt;
    private JButton checkB, depB, widB, exit;
    public double bal=0.0;

    public MenuTable()
    {
    super("ATM");
    setLayout (new FlowLayout(FlowLayout.CENTER));
    depL = new JLabel("Amount to Deposit:");
    widL = new JLabel("Amount to Withdraw:");

    depTxt = new JTextField(10);
    widTxt = new JTextField(10);

    checkB = new JButton("Check Balance");
    depB = new JButton("Deposit");
    widB = new JButton("Withdraw");
    exit = new JButton("Exit");

    add(depL);
    add(depTxt);
    add(widL);
    add(widTxt);
    add(checkB);
    add(depB);
    add(widB);
    add(exit);

    ComputeHandler handler = new ComputeHandler();
    checkB.addActionListener(handler);
    depB.addActionListener(handler);
    widB.addActionListener(handler);
    exit.addActionListener(handler);

    }

    public class ComputeHandler implements ActionListener
    {

    public void actionPerformed (ActionEvent event)
    {
    /* HERE'S THE PROBLEM.. IT DOESN'T ADD THE NEW MONEY AFTER THE USER INPUT A NEW VALUE.. INSTEAD, IT DISPLAYS THE NEW VALUE, NOT ADDING IT TO THE VALUE BEFORE * THE NEW ONE
    *
    /*
    double money=0.0;
    if (event.getSource() == checkB)
    {

    JOptionPane.showMessageDialog(null, "Your current balace is "+bal);
    }

    if (event.getSource() == depB)
    {
    money = (Integer.parseInt(depTxt.getText()));
    bal=+money;
    JOptionPane.showMessageDialog(null, "Successful");

    }

    if (event.getSource() == widB)
    {
    money = (Integer.parseInt(widTxt.getText()));
    if(bal>0)
    {
    JOptionPane.showMessageDialog(null, "Successful");
    bal=-money;
    }
    else if(bal<0)
    {
    JOptionPane.showMessageDialog(null, "Insufficient balance");
    }
    }

    if (event.getSource() == exit)
    {
    System.exit(0);
    }
    }


    }
    public static void main(String[] args) {
    MenuTable menu=new MenuTable();
    menu.setBackground(Color.RED);
    menu.setSize(220, 200);
    menu.setResizable(false);
    menu.setLocation(150, 150);
    menu.setVisible(true);

    }
    }
    Last edited by boybackup; 11-12-2011 at 06:10 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: pls. help on my unknown error

    As volunteers we appreciate a response to replies to your questions since it tells us that you're reading what we post. You may wish to respond to Norm in your previous thread: no-error-but-cant-see-after-logging. Thanks for your cooperation.

  3. #3
    boybackup is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: pls. help on my unknown error

    i'm doing my best in this subject in my school.. but all people have a limitation.. no one is perfect.. i always do my best but i guess still its not good enough..

    my last option is to ask for help to pro's like youu...

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: pls. help on my unknown error

    Quote Originally Posted by boybackup View Post
    i'm doing my best in this subject in my school.. but all people have a limitation.. no one is perfect.. i always do my best but i guess still its not good enough..

    my last option is to ask for help to pro's like youu...
    I'm not sure what your comment above has to do with your problem at hand or my post above. Most folks on receiving a post like mine above, go to the linked thread and post a small comment to the person who tried to help them.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: pls. help on my unknown error

    In your previous thread Norm suggested you add System.out.println() statements to your code so you can better understand what is going on. And it's the same thing here.

    Before:

    Java Code:
    if (event.getSource() == depB)
    {
        money = (Integer.parseInt(depTxt.getText()));
        bal=+money;
        JOptionPane.showMessageDialog(null, "Successful");
    }
    After:

    Java Code:
    if (event.getSource() == depB)
    {
        System.out.println("Processing deposit");
        System.out.println("    bal is initially " + bal);
        money = (Integer.parseInt(depTxt.getText()));
        System.out.println("    money is " + money);
        bal=+money;
        System.out.println("    bal after update " + bal);
        JOptionPane.showMessageDialog(null, "Successful");
        System.out.println("    done!");
    }
    What output is generated when you deposit some money? Did you expect to see that? Does the difference between what you see and what you expected to see shed any light on which line of your code is not doing what you thought it would?

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2011, 02:36 PM
  2. unknown error - really need help
    By smallmos1 in forum New To Java
    Replies: 2
    Last Post: 03-15-2011, 11:46 PM
  3. unknown html:form tag error.Pls help
    By yss1287b in forum New To Java
    Replies: 0
    Last Post: 12-14-2010, 11:31 PM
  4. Unknown NullPointerException Error...
    By ryanonnfire54 in forum New To Java
    Replies: 4
    Last Post: 11-16-2010, 07:23 PM
  5. Unknown error in Jtable...
    By blu_fox88 in forum AWT / Swing
    Replies: 2
    Last Post: 02-23-2010, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •