• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I update a frame class from other classes

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a controller class called from the main method of a jframe inherited object, I need to update the jframe object, how do I do it from the controller

such as


Thanks a lot
 
Campbell Ritchie
Marshal
Posts: 52574
119
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Have you got a frame class with a main method and nothing else in?
If you are creating a Controller, put the main method in a ControllerDemo class (and think of a better name for it). Let your application create the Controller object, and the frame object, and then you can pass the objects references to each other.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, ah, I think in the same way, I can pass an JFrame object reference such as "new CController(this);" to the controller.
Your hint was great.
Jack
 
Campbell Ritchie
Marshal
Posts: 52574
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done It is always good when you can see poeple learning.

Just beware of letting a this reference escape. Letting other classes get hold of a this reference is all right, provided the this is in a consistent state. The one place a this can legitimately be inconsistent is inside the constructor. There is an example here, which is similar to something I remember having seen somewhere on the Ranch earlier.
Have a look at that example, and make sure not to fall into the error shown there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!