celine scarlett

Ranch Hand
+ Follow
since Nov 06, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by celine scarlett

Problem all solved now. I can eventually get some sleep.

Thanks to all for their help.
18 years ago
Hi,

I've got the arrayList working now with the correct add method, except for one small problem. When a user adds a new value to the arrayList, it is added at the position before the current position. The other way of looking at this problem, is simply that the original value is moved forward one position in the arrayList, instead of the new value being placed after the current position.

eg: a user enters 10,20,30,40 and then goes back through the arrrayList to 20. Then they enter 25. This should be placed between 20 and 30, and not between 10 and 20 as is currently happening.

I've tried numerous different options but none produce the desired end result.

My current code is as follows,

Any advice or help appreciated.

Many thanks
18 years ago
Hi,

Thanks for the reply. I've tried using an add method which allows you to specify the index number where you want to a new value, but with this program I have no way to know the index number when a user wants to add a new value. All I have is the 'int current index' value.

I'm assuming I can use this with the add method. I've tried using it in the actionPerformed method, but it produces an addition after every click of the backwards button etc.

What would be the best way to add this method to this program? I thought about adding it using an if statement, but I couldn't think of an effective point to change it to the else statement.

Any ideas or advice appreciated!
18 years ago
Hi,

I've finally managed to get my arrayList based program working, but there is one small item missing. When a user goes through the arrayList, forwards and backwards and then enters a new value it is automatically added to the end of the arrayList.

Does anybody know if there is a way to add this value to the current position in the list?

eg: a user enters 12,21,31,41,51 and then uses the index of these values to go back through the list to 21. They then enter a new value, 53, and want it saved after 21 but before 31.

What would be the best way to achieve this result?

My code for adding to the arrayList is currently as follows,

public class ClickAction implements ActionListener {

public void actionPerformed(ActionEvent event) {

// Parse degrees Celsius as a double
// and convert to Fahrenheit.

String celsiusAsText = tempCelsius.getText();
try { //start of the exception handling
Double celsiusAsDouble = Double.parseDouble(celsiusAsText);
double fahrenheitAsDouble = celsiusAsDouble*1.8+32;
fahrenheitLabel.setText(fahrenheitAsDouble + " Fahrenheit");
celsiusList.add(celsiusAsDouble);
fahrenheitList.add(fahrenheitAsDouble);
celsiusListCurrentIndex = celsiusList.size() - 1;//end of the list
fahrenheitListCurrentIndex = fahrenheitList.size() - 1;//end of the list
} catch(Exception e)
{fahrenheitLabel.setText("? Fahrenheit");}
}
}



Any advice or help appreciated!
18 years ago
Hi,

That's brilliant. Thank you so much for your help. I now have working backwards and forwards buttons.

It's been a long weekend, but I've finally got there.

Have a great week!
18 years ago
Hi,

With alot of help, I've managed to get the actionPerformed methods of the backward and forward buttons going through the arrayList correctly, with the exception of one small problem.

When a user enters a sequence of numbers eg: 22,32,42,52 and then presses the back button, they are taken back to 22, instead of 52. Then the user has to press the forward button. From this point on, the buttons work perfectly, and go backwards and forwards through the list.

Does anybody know why this error might be occurring?

My current code for the actionPerformed methods is as follows,


Any help or advice appreciated!
18 years ago
Hi,

I've managed to get the buttons to alternate between decrementing and incrementing the index values. However, they only jump backwards and forwards to the first and last values in the list.

eg: a list contains 22,32,42,52 and a user presses the backwards button, it will go back to 22 and not 42 from 52 and vice versa

Current code for the two actionPerformed methods is as follows,

I've checked the actionPerformed method for the convert button, but I don't see how that would affect the other buttons. Anyway, the code for that method is as follows,


Any ideas what is causing this problem?

Thanks for the help!
18 years ago
Hi,

Thanks for the reply. I have tried implementing the actionPerformed methods as suggested above, and I get a really weird result. It outputs an error saying 'ArrayIndexOutofBoundsException: -1'. Any ideas why this is happening?

My current is as follows,


I really can't see where the problem is with these methods. It's all very strange.

Any help or advice really appreciated at this stage.

[ January 29, 2006: Message edited by: celine scarlett ]
[ January 29, 2006: Message edited by: celine scarlett ]
18 years ago
Hi,

I've tried that solution. The problem is that by setting currentPosition to 0, for some reason it is ignoring the arrayList, and starting at 0. It then increments the value from 1 upwards and does not go through the arrayList.

Maybe there's a way to link this to the arrayList, but I'm getting really confused at the moment.

Anybody got any ideas?

Thanks.
18 years ago
Hi,

Thanks for the reply. That works correctly for one click of the backwards button, but it will not go back beyond one position.

Any ideas what the problem might be?

Many thanks for the help.
18 years ago
Hi,

With a little help I've finally managed to add an arrayList to my swing program. The problem is now with iteration through this list. When I try to go through the list, it simply jumps straight to the beginning or end of the list, depending on whether I click the backwards or forwards button.

The arrayList is printing out correctly, so I'm guessing the problem must be with the code for the iteration methods.

My code so far is as follows,


I can't seem to see the problem. Any advice or help appreciated.

Many thanks.
18 years ago
Hi,

I've written an actionPerformed method for a basic swing program. This program takes input from a text field and then converts it for the required result. Therefore, there are two doubles produced.

Basically, how would I then add those two results to an array so I could call them from two other buttons?

I'm having real problems linking an array to an actionPerformed method. My current actionPerformed method is as follows,



I really can't seem to see the wood for the trees with this one. Any help appreciated!
18 years ago
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!
18 years ago
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!
18 years ago