samedi 27 juin 2015

java - cannot get field with different initialize using reflection

I have some problem. I don't know what a calling of like this.

class test 
{
        JButton button=new JButton("button");
        JFileChooser fc=new JFileChooser()
        {
            @Override
            public void approveSelection(){
            File f = getSelectedFile();
               if(f.exists() && getDialogType() == SAVE_DIALOG){
                    int result = JOptionPane.showConfirmDialog(this,"The file exists, overwrite?","Existing file",JOptionPane.YES_NO_CANCEL_OPTION);
                    switch(result){
                        case JOptionPane.YES_OPTION:
                            super.approveSelection();
                            return;
                        case JOptionPane.NO_OPTION:
                            cancelSelection();
                            return;
                        case JOptionPane.CLOSED_OPTION:
                            return;
                        case JOptionPane.CANCEL_OPTION:
                 //         cancelSelection();
                            return;
                    }
                }
                super.approveSelection();
            }        
        };
        void test()
        {
        }
}

I have use reflection to get field:

Class cls=Class.forName("test");
Field[]field=cls.getDeclaredFields();
for(Field f : field)
{
    System.out.println (f.getType().getSimpleName()+ " : "+ f.getType());
}

The output is following:

JButton : class javax.swing.JButton
JFileChooser : class javax.swing.JFileChooser

So, I want to get all Object classes inside initialize of JFileChooser like File f, JOptionPane, etc.





Aucun commentaire:

Enregistrer un commentaire