Click to See Complete Forum and Search --> : Urgent help please


oorWullie
03-27-2005, 06:03 PM
hi there, could somebody please look at the code at this address:

http://www.freewebs.com/tempstorage01/calculatorGUI.java

and see if they can see where my problem lies?

i know theres a few bits that are 'off' just now but im not interested in them, what i need to know is why my memory functions do not work.
It seems like its not picking up the variables, im used to lingo so i suppose its me 'global variables' that i cant quite get the hang of in java.

Oh and how do i add together to floats? or doubles? it should be simple i imagine but apparently not, the simple + doesnt seem to do that trick.

any help and i will be very greatfull, thanks

also the other file with the main is here

http://www.freewebs.com/tempstorage01/FinalCalculator2.java

thanks

Kram
03-28-2005, 02:51 AM
just had a quick glimps of the code and it looks to me that you are getting a little confused with your globa variables. In you actionlistener "calculatorActions" class you are defining the variable "memoryNumber" as a local variable, not using the globally set one.

the code:


if (event.getActionCommand().equals("MS"))
{
temp = display.getText();

if (temp != null)
{
Toolkit.getDefaultToolkit().beep();
float memoryNumber = Float.valueOf(temp.trim()).floatValue();
memoryDisplay.setText("M");
}
}


will set a local variable called "memoryNumber" within the actionlistener class and, what you want to do is to keep the actionlistener class as a method of the main class calculatorGUI and implement actionlistener from the calculatorGUI class, im not sure why you are using it as a seperate class...

here is an example of what i mean:
(ill cut out the crap not needed)


class calculatorGUI implements ActionListener
{

...
... set variables other method etc...
...

public void actionPerformed(ActionEvent event){

your code for the buttons goes here... ie.

if (event.getActionCommand().equals("MS"))
{
temp = display.getText();

if (temp != null)
{
Toolkit.getDefaultToolkit().beep();
float memoryNumber = Float.valueOf(temp.trim()).floatValue();
memoryDisplay.setText("M");
}
}

}
} // end of actionPerformed

and so on
} // end of class


i hope i make some sort of sense...If i have made a complete blunder of somesort then im sorry, but thats what i saw...:D