• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPanel communication  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JPanel class that creates a left panel and a right panel. the left panel and right panel both have one button each. What I’m trying to accomplish is when I click on the button in the left panel that it updates the button in the right panel. I have to do this without changing anything in the right panel.
Basically I have to have LeftPanel have a way to keep track of an instance of RightPanel and I would have to do this through the JPanel class.
But I have no clue where to begin on even accomplishing this.
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does it mean to 'update' a button?
 
Ricky Peddicord
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:What does it mean to 'update' a button?


Oh, sorry. Change the text on the button. I know how to do that part though. Its just the part of keeping track of the instance.
 
Sheriff
Posts: 4293
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably the best way to do this is pass the object reference to the left button. The other way is to declare the button outside of any methods, that is, make it a class variable.
 
Ricky Peddicord
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Probably the best way to do this is pass the object reference to the left button. The other way is to declare the button outside of any methods, that is, make it a class variable.


I understand what you are saying about passing the object refence, would you mind showing me a simple example though as I don't think I've seen what this looks like in code before?
 
Knute Snortum
Sheriff
Posts: 4293
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post your code (and UseCodeTags) or a short example, maybe even give it try yourself. If you're really not getting it I can help you along the way.
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ricky Peddicord wrote:Basically I have to have LeftPanel have a way to keep track of an instance of RightPanel and I would have to do this through the JPanel class.


I think you would be better off to have a proper controller class, rather than trying to link view classes together like that.

So this controller class would contain a reference to the LeftPanel and to the RightPanel. It would also be the one which listens to the button in the LeftPanel so that it can cause the RightPanel to be updated when the button is pressed. In fact you already have such a class, I expect. It's the one which builds the GUI.
 
Ricky Peddicord
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Could you post your code (and UseCodeTags) or a short example, maybe even give it try yourself. If you're really not getting it I can help you along the way.


myJPanel.java


myJPanel1.java


myJPanel2.java


I just need kind of a nudge on how to do this as I am clueless x_x

myJpanel2 is not allowed to be modified at all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!