DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    2

    Urgent help please

    hi there, could somebody please look at the code at this address:

    http://www.freewebs.com/tempstorage0...ulatorGUI.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/tempstorage0...lculator2.java

    thanks

  2. #2
    Join Date
    Sep 2004
    Posts
    223
    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:

    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)
    Code:
    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...
    A kram a day keeps the doctor......guessing

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links