File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calculator Memory buttons not working?

 
Joe Grimp
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Grimp
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Justin Fox
Ranch Hand
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic