| Author |
How do I update a frame class from other classes
|
Jacky Luk
Ranch Hand
Joined: Aug 02, 2012
Posts: 201
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
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
Joined: Aug 02, 2012
Posts: 201
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
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.
|
 |
 |
|
|
subject: How do I update a frame class from other classes
|
|
|