i am trying to create such calculation within a texArea which i calculate in one class, and i pass this onto a different class to perform the next calculation with only clic
One thing I do know is that you've got a serious reference problem going on. For example in your first posted actionPerformed method:
if (e.getSource() == payment) {
Payment paymentJ = new Payment(); // ***** line 1 ****
paymentJ.output.setText(output.getText()); // ***** line 2 ****
}
On line 1 above you create a new Payment object, called paymentJ, and on line 2 you change its state, by calling output.setText(...)
. I'm guessing that output is some text component, and you're trying to change the text that it displays, but here's the problem -- while paymentJ refers to a Payment object, it's not the Payment object that is being displayed, which is a completely distinct separate object, and changing the state of the non-displayed one created here by trying to change the text it displays, will have no effect on the output text component in the actualy displayed Payment object.
Similarly in your second posted actionPerformed method:
Main main = new Main();
// double totalR = Double.parseDouble(output.getText());
String cost = main.output.getText(); // ***** line 1 ****
double cost2 = Double.parseDouble(cost); // ***** line 2 ****
On line 1 above you create a new Main object, called cost, and on line 2 you query its state, by calling output.getText()
. But again the Main instance created here is not the same Main object that is being displayed, and again this means that you have at least two (or more) Main objects, only one of which is being displayed, and the data that your extracting from the one created locally here will not reflect the changes made to the one that's displayed. You can test this by placing a println after you extract the text, for example:
Main main = new Main();
// double totalR = Double.parseDouble(output.getText());
String cost = main.output.getText();
System.out.println("cost is currently: " + cost); // ***** add this ****
double cost2 = Double.parseDouble(cost);
I will bet that you'll see a default value that is held by the text component returned, and not a value that was entered by the user or was displaying in the currently visualized Main GUI.
What to do?
For more help, for better help, please improve your question.
Based on your new code,
Payment paymenetJ = new Payment(this);
public Payment(Main main)
this.main = main;