I am having a JDialog created when a menu item is selected 
in a Frame (Simple Scenario). One parameter in the 
constructor of the Dialog is a Class class parameter. 
Within the dialog constructor, I know only that the Class 
class parameter is a JComponent. So it can be a JButton, 
JComboBox, JRadioButton.... etc. etc.

Now when I create the component inside the dialog's 
constructor, how would I determine if it a JButton, 
or JCombobox or JRadioButton.... etc... etc.. so that I can
attach the proper listner.

This is the general look of my JDialog....

public class myDialog extends JDialog implements 
ActionListner, ItemListner (Other listners if required)
{

public myDialog(JFrame parent, Class cls)
{
//at this point I know that for sure (from outside)
//that when the call for the costructor comes, Class
//cls is going to be a JComponent

                       .........
//So then I create the JComponent like this...
JComponent component = cls.newInstance();
component.setVisible(true);

                       ....
//Well when I run the program (full scale completion)
//I can see the component is created. I tested with a 
//JButton, and a JRadioButton. But the question is
//I have to attach the proper listener. How would I
//know inside here (constructor of the dialog) whether
//it is a JButton or JRadio or JCheckbox.... etc..etc.
//to add the proper listener? Further if it is a
//component which requires a text string attached 
//it like in a button or in a RadioButton, I cannot
//use the setText() unless if know for sure the
//setText method is in the subclass. I tried to
//downcast from JComponent. I am getting a
//ClassCastException. 
 }
}

Can anyone throw some light here?



_____________________________________________________
Chat with your friends as soon as they come online. Get Rediff Bol at
http://bol.rediff.com




_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to