wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes To fix an ArrayList API problem.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "To fix an ArrayList API problem...." Watch "To fix an ArrayList API problem...." New topic

To fix an ArrayList API problem....

S. S. Diaz

Joined: Jul 18, 2006
Posts: 6
Hello there!...I have an ArrayList problem(or defect) in Java because everytime this code snippet:


inside the inner class runs, the object "a"(a double variable) won't add to the ArrayList. Is there anything that I can do to solve the problem? Here are my code fragments that is supposed to function well for my calculator project:

class subtractNum implements ActionListener { // an inner class for
// the subtraction.

public void actionPerformed(ActionEvent event){
a = Double.parseDouble(field.getText());
op = "-";
} else {
if (op == "-") {
a = a - Double.parseDouble(field.getText());
} else {
if (op == "+"){
a = a + Double.parseDouble(field.getText());
if (op == "*"){
a = a * Double.parseDouble(field.getText());
if (op == "/"){
a = a / Double.parseDouble(field.getText());
field.setText(a + "");
op = "-";
b = Double.parseDouble(field.getText());

new NumButtonPackage();

Thankz in advance!
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

Hi, this is a JSP forum, post to the beginner forum next time

Why is "a" removed ? Maybe this could be a hint :

field.setText(a + "");
b = Double.parseDouble(field.getText());

[My Blog]
All roads lead to JavaRanch
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Moving to Java In General (Beginner)

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112

Are you aware of the fact that the value of "a" changes between the check in the if and the call to add?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Don't get me started about those stupid light bulbs.
subject: To fix an ArrayList API problem....
Similar Threads
accessor methods for Swing components
JTextFields & storing data
blank fields
Textfield Problem
KeyListener with Control key