aspose file tools
The moose likes Swing / AWT / SWT and the fly likes How do I update a frame class from other classes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "How do I update a frame class from other classes" Watch "How do I update a frame class from other classes" New topic
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
    
    4
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
    
    4
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How do I update a frame class from other classes
 
Similar Threads
Basic question on objects and references to objects
event handling for med sized MVC app
Still having some trouble with Observer/Observable
Thread Safe Code
MVC in swing