Please let me explain what I'm trying to do - I think the headline explains it something like this, but I'm not sure I'm going to do it right, so please correct me if I'm wrong!
I created a custom dialog using a LayeredPane . Essentially, a jPanel maps to POPUP_LAYER , so it appears on top of the main content. This panel contains a simple group of controls, "label-textbox-okay-cancel". I will call it the "Dialog Panel".
What I'm trying to do: When I click a button in the main window (contained in LayeredPane ) a dialog box will appear and allow the user to enter text, then click "OK" or cancel. This is all quite simple, but I would like this code to be reused, which means that other buttons in the main window will bring up the same dialog box, but with different text in the shortcut.
This, of course, requires that I turn on some kind of callback function, so that the ok button on the dialog panel launches the correct code according to the button that called it.
My current attempt is to save a string that will contain the name of the function that should be run when the user clicks the OK button on the dialog bar. I am trying to recover this string and convert it to a function name, and so far I have found many references to Reflection, many of which suggest that this is not a good idea.
In any case, I was unable to get any sample code to work, because I do not understand that "obj" is in the code below, and I am unable to call the method:
method = obj.getClass().getMethod(myCallbackString);
My questions:
First, am I even going to do it right? I am more than open to suggestions, but please try to keep it as simple as possible, because I'm really starting!
Secondly, what is “obj” in the above code? I would really like to know, even if it’s not how I should do something!
My other thoughts include: Should my dialog bar be in its class, and if so, how do I pass the callback function?
Any help or advice would be greatly appreciated.
By the way: In response to the question "why not use the usual dialogue?" I can only say that I'm experimenting now, and I just want to see if I can do it!
MVK