Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Calculator Memory buttons not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calculator Memory buttons not working?" Watch "Calculator Memory buttons not working?" New topic
Author

Calculator Memory buttons not working?

Joe Grimp
Greenhorn

Joined: Apr 02, 2006
Posts: 15
Here is my calculator code -



Any ideas why the memory buttons aren't working? Am i parsing an empty string here -



If i am how do i fix this problem? Thanks.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
What do you mean by "not working"? What happens when you press the memory button? Does your app throw an exception? Does the "memory" contain the wrong value? Or does something else happen that is unexpected? Please give us more details about what happens and we can help you out.

With that said, you should add some System.out.println() calls (or find some other way) to display the values of the variables involved. This will often help you see what is happening in your code.

Layne


Java API Documentation
The Java Tutorial
Joe Grimp
Greenhorn

Joined: Apr 02, 2006
Posts: 15
It says "Error: Invalid Input" at the bottom of my applet once you press one of the memory function buttons. Has anyone got any ideas how i can get these buttons to work? Thanks.
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
you need to intitialize the String object Arg. when you are initializing the buttons and labels and stuff...

i believe this will help you out..


You down with OOP? Yeah you know me!
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
and use event.getSource()

arg = event.getSource()



if (arg == "buttonname")
{
//do this
}

//or


if(event.getSource() == "buttonname")
{
//do something
}

this will help your buttons out..... but instead of "implements actionlistener.

and you can also do:

JLabel Label;

if(event.getSource() == addButton)
{
int answer = (int) label.getText();

int count += answer; // initialize count at the top.
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
and use event.getSource()

arg = event.getSource()



if (arg == "buttonname")
{
//do this
}

//or


if(event.getSource() == "buttonname")
{
//do something
}

this will help your buttons out..... but instead of "implements actionlistener.

and you can also do:

JLabel Label;

if(event.getSource() == addButton)
{
int answer = (int) Label.getText();

int count += answer; // initialize count at the top.
// but have a clear button to clear the answer
// variable.
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Calculator Memory buttons not working?
 
Similar Threads
GUI
Calculator clear button not working...
2D Array Help
Convert Swing class to Applet?
Please rescue me out