Results 1 to 17 of 17
- 09-28-2008, 12:44 AM #1
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
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-28-2008 at 12:56 AM. Reason: mistake
- 09-28-2008, 12:58 AM #2store a number in the memory
Do you have a program that you are trying to write that shows what you mean?
- 09-28-2008, 11:08 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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.
- 09-28-2008, 11:20 AM #4
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
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
- 09-28-2008, 11:23 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
- 09-28-2008, 11:28 AM #6
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
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
- 09-28-2008, 11:38 AM #7
Lots of responses in the cross post on the Sun Java forum at ThreadID=5335092
db
- 09-28-2008, 11:46 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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.
- 09-28-2008, 11:50 AM #9
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
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
- 09-28-2008, 11:53 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Can you post your code to see here. Just looking the code you have already posted here, can't pointed more.
- 09-28-2008, 11:54 AM #11
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
"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
- 09-28-2008, 12:07 PM #12
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
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 complexLast edited by Ak-Emm; 09-28-2008 at 12:10 PM.
- 09-28-2008, 12:11 PM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Ok, are you working on a Java IDE? If so it's not difficult.
And also if your code contains following,
Java Code:memoryStore(); {
- 09-28-2008, 12:14 PM #14
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
- 09-28-2008, 12:16 PM #15
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
- 09-28-2008, 12:24 PM #16
Member
- Join Date
- Aug 2008
- Posts
- 17
- Rep Power
- 0
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
- 09-28-2008, 12:49 PM #17
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Yes, quite similar thing you have to do.
Similar Threads
-
How to store keys in KeyStore use java code
By lc666111 in forum Advanced JavaReplies: 1Last Post: 09-29-2008, 09:25 PM -
How to store 5 numbers from a file into 5 seperate variables?
By kewlgeye in forum New To JavaReplies: 4Last Post: 06-09-2008, 05:44 PM -
Computing prime numbers in Java
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 09:39 PM -
store file
By kazitula in forum Java AppletsReplies: 0Last Post: 02-17-2008, 10:45 PM -
random numbers without using java funtions
By carlos123 in forum New To JavaReplies: 8Last Post: 11-16-2007, 11:13 AM
Bookmarks