I have a program with 2 panels, each with it's own class.
LeftPanel and RightPanel.

Whenever I click a button that does some calculations (like calculating total assets amount) in one of the panels, it doesn't update that info for the other panel.

For example....I have this seperate class that both the panel classes call on

public class Money {

	public int money;
	public boolean first_run;
	
	public Money(int money){
		this.money = money;
	}
	
	public int getMoney(){
		if (first_run==false){
			money = 100;
			first_run=true;
		}
		return money;
	}
	public void setMoney(int money){
		this.money = money;
	}
}

When I setMoney in the RightPanel, I need it to change the textarea in LeftPanel.

Is it something like repaint()? Or some other method that I'm unaware of? (plz show how it might work too since I'd be unfamiliar with it)

Much Gracias,
Slyvr

Recommended Answers

All 4 Replies

You haven't posted your panel classes/main class code.

You haven't posted your panel classes/main class code.

It's helluz long. Several hundred lines of code for each panel.

But I'll try to summarize

public class RightPanel extends JFrame {
	public RightPanel(){
		//btn1 action listener
			//Determine what is selected to buy
			//calculate money changes
			money.setMoney(wallet);
			//Something here that updates LeftPanel?
		//end btn1
	}
}
public class LeftPanel extends JFrame {
	public LeftPanel(){
		//btnStart action listener
			wallet = money.getMoney();
			System.out.println(wallet);
			txtMoney.setText(Integer.toString(wallet));
		//end btn
	}
}

Also, I've noticed that when I click the Start Day button in left panel it changes money back to 100. I think it'd have to do with the first_run in the Money class, but I don't see why it would change it if it should've already changed when I setMoney in the RightPanel class the first time.

Make a method in the LeftPanel class for setting the text, which takes the amount as a paramater. Then call that method after you set the new amount.

public class RightPanel extends JFrame {
	public RightPanel(){
		//btn1 action listener
			//Determine what is selected to buy
			//calculate money changes
			money.setMoney(wallet);
                        LeftPanel.showAmount(money.getMoney());

			//Something here that updates LeftPanel?
		//end btn1
	}
}

Just an idea

I've tried something like that before and it didn't quite work. Besides I need the LeftPanel to update some things in the RightPanel too and you can't have both of them able to call each other.

Should I just jumble all the code in LeftPanel and RightPanel into one class? It'll be the easiest solution I can think of but it'll be one big ass, confusing, jumble of code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.