In my program I assign objects from one class to objects of the same type in another class ,that worked for me except with bigdecimal here is a code snippet
public class MasterDetail extends JFrame {
private ArrayList<SellBean> sellRecords;
private JLabel totlLbl;
private BigDecimal totalProfit;
in the button action i call the constructor of the other class and pass these objects to it
previewBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (!(sellRecords.isEmpty())) {
new Preview(sellRecords, totlLbl,totalProfit);
}
in the other class i create a corresponding object to assign to the received ones
public class Preview extends JFrame {
private ArrayList<SellBean> sellRecords;
private JLabel totlLbl;
private BigDecimal totalProfit;
public Preview(ArrayList<SellBean> sellRecords, JLabel totlLbl,
BigDecimal totalProfit) {
this.sellRecords = sellRecords;
this.totlLbl = totlLbl;
this.totalProfit = totalProfit;
}
}
the problem is when i make any change to the sellRecords or totlLbl of the Preview class that change reflects to the other class MasterDetail but when i change the bigdecimal object totalProfit of Preview it changes in Preview but not reflects the other class as the previous objects . here is the code where i try to change values in Preview class and want to reflect MasterDetail class
btnNewButton = new JButton("delete item");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (table.getSelectedRow() >= 0) {
SellBean bean = Preview.this.sellRecords.get(table
.getSelectedRow());
Preview.this.totlLbl.setText(Double
.valueOf(Preview.this.totlLbl.getText())
- (Double.valueOf(bean.getSELL_PRICE().toString()) * Double
.valueOf(bean.getQUANTITY().toString()))
+ "");
BigDecimal profit = (new BigDecimal(bean.getSELL_PRICE()
.toString()).subtract(new BigDecimal(bean
.getBUY_PRICE().toString())))
.multiply(new BigDecimal(bean.getQUANTITY()
.toString()));
Preview.this.totalProfit = Preview.this.totalProfit.subtract(profit);
Preview.this.sellRecords.remove(table.getSelectedRow());
}
this worked for "totlLbl" and "sellRecords" but not for "totalProfit" . Can anyone help me?