aspose file tools*
The moose likes Beginning Java and the fly likes storing values in an array and accessing them elsewhere in the program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "storing values in an array and accessing them elsewhere in the program" Watch "storing values in an array and accessing them elsewhere in the program" New topic
Author

storing values in an array and accessing them elsewhere in the program

celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I'm writing a basic conversion program for celsius and fahrenheit temperatures. These values are input into a textfield and then converted in a simple actionPerformed method.

Basically, I'm now struggling with the array part. How do I add these values for the temperatures to an array so I can then access them elsewhere in the program.

My code for the actionPerformed method is as follows,


I'm basically trying to save the temperature values for each user session, and link them to a forward and backward button. These values do not have to be saved after the user exits the program.

Any advice or help appreciated!
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
Hi
Better use a java bean for storing these kinds of things. I mean temperature,as well as other details of the user. If you have one similar bean then write getter and setter methods for storing this temperature.


Whats the need of arraylist?? You said you have to store only 1 single temperatiure value.


SCJP 1.4, Brainbench
LinkedIn - Blog
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I need to store as many values as the user inputs and converts during the run of the program.

eg: a user could input 10 degrees celsius and convert it to a fahrenheit value, then 25 degrees celsius and convert that and so on. They would then need to be able to go backwards and forwards through these values.

Therefore, I just assumed an array was the best way to store and access these values, but I'm not sure how to implement this solution.

Any ideas or help appreciated!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It sounds like an ArrayList might be a better tool than an array. I say this because you don't know exactly how many numbers you will be storing. Most likely this ArrayList should be a member variable somewhere, but I'm not sure which class it should belong to since you haven't posted any description of your design.

Layne


Java API Documentation
The Java Tutorial
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: storing values in an array and accessing them elsewhere in the program