Results 1 to 17 of 17
  1. #1
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Question how to Store and recall numbers in java ?

    Question

    is there a java method to store a number in the memory and recall it
    like MS and MR in the Microsoft Calculator?

    when the MS button is clicked it store the numbers
    When MR button is clicked it recalls the number


    lets say ive used
    i.e using the String s method which is simple straight forward

    actionPerformed Event e blaah blah blah
    //add your handling code here


    Java Code:
    String s;
            intA;
            double Temperature;
            s=textFieldA.getText();
           A=Integer.parseInt(s);
           Temperature= (double)Math.round(A);
           s=String.valueOf(Temperature);
          txtFieldSouthCc.setText(s);



    now when the MS button is clicked it stores both the values in "textFieldA" and "Temperature" to the memory

    and when the MR button is clicked it recalls the stored numbers textFieldA,Temperature from the memory and sets it back
    using the .setText("") method in "textFieldA" and "Temperature"

    is this possible ?

    your solutions are welcome:confused:
    Last edited by Ak-Emm; 09-27-2008 at 11:56 PM. Reason: mistake

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default

    store a number in the memory
    Not sure where "memory" is for you. Do you mean in a variable in your program or on a disk file?
    Do you have a program that you are trying to write that shows what you mean?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    There is no such memory location for Java. All what you have to do is use variables in correct type and correct access levels and handle them as you wish. Important thing is until your application is running, values are not destroy if you are define in right way. Same thing is happen in MS calculate also, all values are available only for one instance.

  4. #4
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Question yes variable sort

    when the MS button is clicked as mentioned earlier
    both the values in "A" and "Temperature" are stored

    when MR button is clicked it recalls the saved variables

    back to "A" and "Temperature" textfields using the setText("") method

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    There is no such memory location for Java. All what you have to do is use variables in correct type and correct access levels and handle them as you wish. Important thing is until your application is running, values are not destroy if you are define in right way. Same thing is happen in MS calculate also, all values are available only for one instance.
    actually there is

    if you have a Windows OS i.e Vista, XP 2k

    %SystemRoot%\system32\calc.exe
    copy and paste this in Run


    look at the buttons

    MC ----memory clear
    MR-----memory recall
    MS----memory store
    M+----add new memory to store

    there should be a method in java for this thats what im trying to find out

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default

    Lots of responses in the cross post on the Sun Java forum at ThreadID=5335092

    db

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Should be the quite same thing should be happen in calculator as I said earlier. In more depth in windows it handle with memory locations actually. Reason is that windows develop on low level languages. May be written in C/C++. In that case you can deal with memory. But in Java you can't. So use correct variables.

    I don't think you can find the exact way how it develop on MS cal. Because windows is not an open source OS and they not allowed to know such things to public.

  9. #9
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    under MS --- memory store button
    Action Performed (event e);
    add handling code here//


    double StK1;
    double Stk2;

    memoryStore(); {
    Stk1= Double.parseDouble(textFieldA.getText());// gets client number 1
    Stk2= Double.parseDouble(textFieldB.getText());// gets client number 2

    this stores the numbers


    now under the MR memory recall button
    Action Performed event e;
    // add handling code here thingi:

    memoryRecall() {
    textFieldA.setText(String.valueOf(Stk1)); recalls client 1 stored value
    textFieldA.setText(String.valueOf(Stk1)); recalls client 2 stored value


    this works partially but its not fully functional cause i get
    Throws Unsupported exceptions error so nothing happens

    where am i wrong that is the question to solve this? this is where im stuck

    your help is kindly appreciated

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you post your code to see here. Just looking the code you have already posted here, can't pointed more.

  11. #11
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    "Lots of responses in the cross post on the Sun Java forum at ThreadID=5335092

    db"




    for better flexibilty of solutions ive posted in both sites
    all experts point of views are valuable

  12. #12
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    the code is too long so i tried to simplify it by cutting it down

    just under actionPerformed event e

    i want to trigger the buttons thats all

    the declarations are all set this is just an experiment so i could work on something more complex
    Last edited by Ak-Emm; 09-28-2008 at 11:10 AM.

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Ok, are you working on a Java IDE? If so it's not difficult.

    And also if your code contains following,

    Java Code:
    memoryStore(); {
    it's wrong, define a method in wrong way.

  14. #14
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Should be the quite same thing should be happen in calculator as I said earlier. In more depth in windows it handle with memory locations actually. Reason is that windows develop on low level languages. May be written in C/C++. In that case you can deal with memory. But in Java you can't. So use correct variables.

    I don't think you can find the exact way how it develop on MS cal. Because windows is not an open source OS and they not allowed to know such things to public.
    thanks in that case ill have to work out a stack method which i havent mastered fully though
    thanks for your time ........P

  15. #15
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Ok, are you working on a Java IDE? If so it's not difficult.

    And also if your code contains following,

    Java Code:
    memoryStore(); {
    it's wrong, define a method in wrong way.
    yes an IDE NetBeans 6

  16. #16
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    class Memory Bank{
    private void memoryRecall() {

    textFieldA.setText(String.valueOf(Stk1)); recalls client 1 stored value
    textFieldA.setText(String.valueOf(Stk1)); recalls client 2 stored value
    }
    }

    something like that

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. How to store keys in KeyStore use java code
    By lc666111 in forum Advanced Java
    Replies: 1
    Last Post: 09-29-2008, 08:25 PM
  2. Replies: 4
    Last Post: 06-09-2008, 04:44 PM
  3. Computing prime numbers in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:39 PM
  4. store file
    By kazitula in forum Java Applets
    Replies: 0
    Last Post: 02-17-2008, 09:45 PM
  5. random numbers without using java funtions
    By carlos123 in forum New To Java
    Replies: 8
    Last Post: 11-16-2007, 10:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •