I have a buying system set up in one class (the Right Panel class) and it's working great, but my text field for displaying money available is in the Left Panel class.

When I click the buy button, it should subtract from the money amount and re-display the new money amount. This is the method I'm using (but it's not working)...

Right panel class

LeftPanel leftPanel = new LeftPanel();
//inside the button action listener
wallet -= InvPrice[comboIndex];
leftPanel.setMoney(wallet);
//end button action listener

Left panel class

public int getMoney() {
		moneys = Integer.parseInt(txtMoney.getText());
		return moneys;
	}
	public void setMoney (int money) {
		this.moneys = money;
		txtMoney.setText(""+money);
	}

I think this would work, but the problem might be that it's not updating the left panel?

Edited 5 Years Ago by Slyvr: n/a

Not originally, but I just added it. That's not related to the issue though.
The problem is doing calculations to the wallet amount in the right panel and then setting that amount onto the text field in the left panel.

Not originally, but I just added it. That's not related to the issue though.
The problem is doing calculations to the wallet amount in the right panel and then setting that amount onto the text field in the left panel.

Of course it is related to your issue. If your get method returns the correct value your code works.
There is nothing wrong with what you have posted, meaning your problem lies elsewhere.

Have you set your component to be focusable? have you added the listener?

Edited 5 Years Ago by Akill10: n/a

I just checked it using the getMoney() and it's definitely setting the money correctly into the left panel. So, the issue is the text field not changing it's text.
I've never used setFocusable listeners. Do you know of a good link for that? Not sure what it would be called exactly.

This article has been dead for over six months. Start a new discussion instead.