NetBeans: accessing class from MyAppView.java - netbeans6.8

When I add an actionperformed event to a button, it generates the TODO section.
However, I would like for it to call a public method defined in MyApp.java, instead of having to define the method inside the MyAppView.java
How can I do this ? Tell MyAppView.java to get the methods and classes from MyApp.java ?

If I understand you correcty:
MyApp.java should implement ActionListener interface, then when creating button. Add object of the class MyApp to listen for actions on this button.
button.addActionListener(myApp);

Related

Method not called from on-tap event in polymer2

In Polymer1 I used
on-tap="exportAsCsv"
in my template! When I use this in a Polymer2 Component (ES6 class syntax) it does not work (Event is not called).
Are you extending Polymer.GestureEventListeners.
You need to extend them in order to use gesture event
class TestEvent extends Polymer.GestureEventListeners(Polymer.Element) {
Please have a look at documents for more help.

How to check Custom Element is registered?

Some method creates new instance of my custom element (created with polymer) and attaches it on page. But I want to check is Element registered before add it and print error to console in bad case. I mean what if I forgot import component html declaration:
<!--I forgot write it in my HTML file -->
<!--<link rel="import" href="packages/visualytik/vis_starter.html">-->
So, in case when I forgot import I want to print error in console.
I know one tricky method:
import 'my_custom_component.dart';
Element component = new Element.tag('my-custom-component');
bool registered = component is MyCustomComponent;
But it's hard method because we should create component first and have to import MyCustomComponent.dart in dart file. Can I check it in other way? Something like:
document.isRegistered('my-custom-component');
Update3
You can also use the new #HtmlImport annotation. If you import the class, then you can be sure you also have imported the HTML of the element. See also https://stackoverflow.com/a/29710355/217408
Update2
See Hunting down unregistered elements
Update
Use a custom constructor in your elements class and do the registration there but only if it wasn't done already.
class MyCustomComponent extends ... {
bool _isRegistered;
bool get isRegistered => _isRegistered;
factory MyCustomComponent() {
if(!isRegistered) {
registerElement();
_isRegistered = true;
}
return new Element.tag('my-custom-element');
}
}
and then create new instances like
new MyCustomElement();
and you can always be sure the element is registered only once (but you always need to use this constructor of course).
Original
If you register your elements by calling document.RegisterElement() yourself instead of relying on Polymer for example, you need to hold a reference to the constructor reference document.RegisterElement() returns, otherwise you won't be able to create an instance of the element.
Therefore you just need to check if you already have a reference to the constructor. See also https://developer.mozilla.org/en-US/docs/Web/API/Document/registerElement

In AS3, how do I run code when a when the movie starts?

I'm making a level editor for my game, and would like to be able to access a list of all the classes included in my game. I have a static function in my Main class:
public static function register(c:Class, category:String):void {
if (classRegister[category] == null) {
classRegister[category] = new Array();
}
classRegister[category].push(c);
}
Then, in each class I want registered, I put a static initializer:
{
Main.register(prototype.constructor, "motion");
}
However, the static initializers only get called when the class first gets used. Is there a way for a class to force itself to be used right when the game starts? I'm aware that I could explicitly list all the registered classes in the Main file, but that's suboptimal in that the Main file would have to be edited whenever a new class is added that wants registration.
Thanks,
Varga
List all the class definition in the ApplicationDomain, and filter them based on a naming convention or a type (an interface?).
To achieve this, you can use ApplicationDomain.getQualifiedDefinitionNames() (docs), but only if you target FlashPlayer 11.3+.
As a side note, you MUST reference this class somewhere, as a class field so the compiler knows it must include this class in the SWF. You can also put the classes you want to reference inside a SWC library and use -compiler.include-libraries as compiler setting (in that case I wonder if your static initializers gets called?).

Programmatically remove a listener added using FXML?

I am adding a listener using FXML:
<RadioButton onAction="#onSelectionChanged" />
Now I need to temporarily disable this listener programmatically.
Now I could set some boolean variable "listenerDisabled" and check this variable in the listener, but I want a way to disable a listener without changing it - so I want to remove it.
The problem here is: How do I reference the listener in my code, so I can use the following?
RadioButton.selectedProperty().removeListener(<what to place here?>)
Thanks for any hint!
Add an fx:id specification to your fxml:
<RadioButton fx:id="myRadio" onAction="#onSelectionChanged" />
In the corresponding controller for the fxml, use the #FXML notation to have the FXMLLoader inject a reference to the radio button into your controller:
#FXML RadioButton myRadio;
To get a reference to the listener, invoke getOnAction:
EventHandler<ActionEvent> myRadioActionEvent = myRadio.getOnAction();
To remove the listener, use setOnAction:
myRadio.setOnAction(null);
To add the listener back again, use setOnAction again:
myRadio.setOnAction(myRadioActionEvent);
I didn't try any of the above, but I don't see why it would not work.

Procedure to use the result from a textbox inside a popup - ActionScript

I am relatively new to ActionScript (have started with it 2 months ago), and have a little doubt of 'procedure' or 'technique' related to passing information between objects.
I have made a class that Pops-up a window that contains a panel with a textbox and two buttons, one for accepting, other for cancelling. It should work as a prompt in which you enter some text, and then if you like the changes, you accept, else, you cancel and the text you entered is discarded.
The thing I'm not sure how to handle is how to receive the text, once the user presses 'Accept', from the class I want to receive it from.
So, the approach I took is a bit cumbersome: firstly, when launching the popup, I associate with it a function (called onResult() in the code) from the 'class that launches', which will be called after the user presses the 'Accept' or 'Cancel' buttons; secondly, to get the text that the user inserted in the box, I keep a reference to it public from my class.
Please have a look at the code here:
http://pastebin.com/Kmud8rBe
I've also programmed in Android before, and the approach there would be much cleanier, just putting the text result from the popup inside a bundle inside an intent, and receiving it from the launched class. Here, I have to pass functions and such, which I don't like at all (although it works!).
So, my question is, for you ActionScript gurus out there, how would you approach this?
Thanks and regards!
pepillo
good that you created a class for your popup-functionality but why did you make all functions static? normal class with normal methods would be better ... and let the class extend from Sprite so that you can add the instance right to the stage.
package
{
import flash.display.Sprite;
public class Popup extends Sprite
{
public function Popup (label:String)
{
// add text and buttons ...
}
}
}
then you can just say:
var pop:Popup = new Popup("message");
addChild(pop);
and to get the data back after the popup is closed you would do sth like this:
private function onPressedAccept(event:MouseEvent):void
{
var text:String = _label.text;
// dispatch a custom event which saves the text as its data
dispatchEvent(new MyEvent(MyEvent.ACCEPT, text));
// close popup ...
parent.removeChild(this);
// or you would remove the popup in the ACCEPT eventlistener ...
}
listening for accept/cancel:
var pop:Popup = new Popup("message");
addChild(pop);
// add eventlistener
popup.addEventListener(MyEvent.ACCEPT, onAccept);
popup.addEventListener(MyEvent.CANCEL, onCancel);
private function onAccept(event:MyEvent):void
{
trace(event.data);
}
link about creating custom events:
http://www.8bitrocket.com/2007/7/31/Creating-Custom-Events-In-Flash-AS3-ActionScript-3/