I have a class that functions as an async TCP Client. In that class, I have a callback function, such as Client_Connected. This fires when my TCP Client has been connected. In my main viewcontroller class, I have an instance of the TCPClient and a label that I want to display the status of the tcpclient.
My question is, in the callback function of the tcpclient class, how can I reference and set the label's text in my mainviewcontroller's class?
When you create your TCPClient class, pass in a reference to your parent class (or just a reference to the label you want to update) - then your "child" class will have access to the element on the "parent" that needs to be updated.
There are probably other approaches, but this is fairly common.
Related
So, if I had something like
class Event {// . . .}
class Children extends Event {// . . .}
class Second extends Event {// . . .}
Would there be any way to retrieve the Children and Second class objects, using the the parent class Event?
Would there be any way to retrieve the Children and Second class objects, using the parent class Event?
No. Given just the code you show, there would not be any way to identify all subclasses of Event in plain Javascript. A parent object is not informed in any way when a subclass is defined, nor is any global catalog maintained. A subclass definition stands on its own and the fact that it subclasses/extends the Event class is not saved anywhere or registered anywhere. It's just information that is used when an instance of the subclass is actually created.
If you wanted to manually keep track of such a thing, you could create your own catalog of sub-classes and then make your code register everything in that catalog.
I have a UISwitch that is in side my UIView. I would like the UISwitch to use a method that I defined in the protocol, and then have another class use the method. This is my first time trying to use a protocol, and I can't seem to figure out how to link up my UISwitch to the method call in the protocol.
This is my protocol:
#protocol responderForOptionalSwitch <NSObject>
#required
- (IBAction) onOffSwitch:(id)sender;
#end
But this method doesn't show up under received actions in the connections inspector.
A protocol is a list of methods that an object should (or, in some cases, must) implement. It is not an implementation of your method itself. To see it show up in IB, you should implement the method in the view/controller (the .h/.m) that your switch belongs to (i.e.: what xib is it in?).
WHAT I HAVE is a standard JavaFX application: Main.java, MainController.java & main.fxml. To add custom component, I created CustomComponentController.java and custom_component_controller.fxml.
PROBLEM is that in CustomComponentController methods I need to reference other methods and standard components from MenuController. I add public static MainController mc; to MainController class body, so that it can be seen from CustomComponentController (MainController.mc.neededMethod()). Then I try to pass everything to it in MainController.initialize() method (mc = this;) - when debugging this breakpoint, I see this full of components instances, but mc remains with null components afterwards.
QUESTION is how to reference the running instance of MainController to use its components and methods in other classes and to crossreference different custom components from each other? How to clean MainController code from event handlers and assistance methods of components by moving it all to component's own class?
I tried the following approaches, but found no way to make them work without errors:
Accessing FXML controller class
How can I access a Controller class in JavaFx 2.0?
JavaFX 2.0 + FXML. Updating scene values from a different Task
JavaFX 2.2 -fx:include - how to access parent controller from child controller
The problem can be solved if you comply the following conditions:
Not only public, but obligatory static MainController mc should be.
Do not forget id in fxml for CustomComponentController: <CustomComponentController fx:id="cc"/>, where cc is the name of the "#FXML imported" CustomComponentController in your MainController class.
Omit parameter fx:controller="main.CustomComponentController" in custom_component_controller.fxml as it results in "Controller value already specified" error (a conflict between main.fxml and custom_component_controller.fxml markup declared controllers).
Put mc = this; in the beginning of MainController's initialize() method. Before using mc in CustomComponentController class, check if it's not null. It can be null when all components, including CustomComponentController, are instantiated at application startup, but there is no mc instance yet. MainController method initialize() where MainController is instantiated is called after components are loaded. Therefore better practice is to use approach in the next paragraph.
In main.fxml create primary component of the same type that CustomComponentController and with the only fx:id parameter. Replace primary component with your CustomComponentController by creating reloadCustomComponents() method and calling it from CustomComponentController's initialize() method. Do it by adding the following to reloadCustomComponents() method:
customComponentAnchorPane.getChildren().remove(customComponent);
customComponent = new customComponent();
customComponentAnchorPane.getChildren().add(customComponent);
Thus all components can be placed outside CustomComponentController with all their methods and reloaded at the startup of the apllication. All component declarations stay in MainController class and can be reached through MainController mc reference. No duplicate creating of components in detail with parameters is needed.
Your problem looks like the classic catalog-crud forms updating, I implemented an interface that I called Updatable with an update method so I could reference any catalog form with any crud form easy after passing Controller Main Class as the UserData Property of the Child Root Component's Form
Hope it Can Solve your problem
How to display class canvas for menulist in a class not midlet and it's class call in midlet?
In the class that extends MIDlet, obtain an instance of Display object using getDisplay API with the instance of MIDlet passed as parameter to that method. Make that Display object available where you need to use it (study Java basics if you don't know how to do that)
Whenever you need to display a canvas (or any other Displayable object for that matter), use display object mentioned above to invoke setCurrent method with an instance of canvas passed as parameter to that method
Getting interested in learning ATL, I started reading this tutorial and I got confused at reading this (also related):
If you want to extend the capabilities of a predefined window class, such as the button or list box controls, you can superclass it.
Why is it called super-classing instead of sub-classing?
Super-classing is writing a new class, that would behave as it it was a new control altogether. A CColoredButton inheriting from CButton would be superclass, when you create instance of CColoredButton
When you already have a control (probably on resource), you may subclass it. Here the "control" in picture is being handled differently and hence the term subclass.
Any class may behave as super class or subclass. You would call some of SubclassXX function/method to subclass already existing control. You would create instance of a control at runtime by allocating the C++ object (CColoredButton) by calling its Create method - here the term super-class.