Results 1 to 5 of 5
Thread: pls. help on my unknown error
- 11-12-2011, 05:06 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 3
- Rep Power
- 0
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 05:10 PM.
-
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.
- 11-12-2011, 05:18 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 3
- Rep Power
- 0
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...
-
Re: pls. help on my unknown error
- 11-13-2011, 11:34 PM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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:
After:Java Code:if (event.getSource() == depB) { money = (Integer.parseInt(depTxt.getText())); bal=+money; JOptionPane.showMessageDialog(null, "Successful"); }
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?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!"); }
Similar Threads
-
Unknown error during runtime in space craft game code execution...
By dino_prd in forum New To JavaReplies: 0Last Post: 11-04-2011, 01:36 PM -
unknown error - really need help
By smallmos1 in forum New To JavaReplies: 2Last Post: 03-15-2011, 10:46 PM -
unknown html:form tag error.Pls help
By yss1287b in forum New To JavaReplies: 0Last Post: 12-14-2010, 10:31 PM -
Unknown NullPointerException Error...
By ryanonnfire54 in forum New To JavaReplies: 4Last Post: 11-16-2010, 06:23 PM -
Unknown error in Jtable...
By blu_fox88 in forum AWT / SwingReplies: 2Last Post: 02-23-2010, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks