Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 8:37 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ]  Bookmark and Share
Author Message
 Post subject: Without casting, is there anyother way?
PostPosted: Sat May 19, 2007 6:41 pm 
Offline

Joined: Sat May 19, 2007 6:34 pm
Posts: 0
((ChildPanel)aPanel).aButton without casting like this,
is there any other way of doing it?


Code:
package hiding.test;

public class MainTest {
   public static void main(String[] args) {
      
      MainWindow aMainWindow = new MainWindow() {
         public ChildPanel createPanel()
           {
              return new ChildPanel();
           }
         
         // --- 2nd ChildPanel
//         public SecondChildPanel createPanel()
//           {
//              return new SecondChildPanel();
//           }
         
         // --- 3rdChildPanel
//         public ThirdChildPanel createPanel()
//           {
//              return new ThirdChildPanel();
//           }         

      };
   }         
}


package hiding.test;

public class ParentPanel {

   public String aButton;

   public ParentPanel() {
      System.out.println("Hi, parent!");
      init();
   }
   
   public void init() {      
      aButton = new String("aButtonAtParent");
   }
}

package hiding.test;

public class ChildPanel extends ParentPanel {
   public String aButton;
   
   public ChildPanel() {
      System.out.println("Hi, Child!");
      init();
   }
   
   public void init() {      
      aButton = new String("aButtonAtChild");
   }
}

package hiding.test;

public class MainWindow {
   ParentPanel aPanel ;
   
   public MainWindow() {
      aPanel = createPanel();
      
      System.out.println("aPanel.aButton=" + aPanel.aButton);
      System.out.println("((ChildPanel)aPanel).aButton=" + ((ChildPanel)aPanel).aButton);

                                 //--- so many instance of aPanel...
      // aPanel.aButton
      // aPanel.aLabel etc ...
   }

   public ParentPanel createPanel() {
      return new ParentPanel();
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 11, 2007 11:19 am 
Offline

Joined: Tue Dec 19, 2006 3:58 am
Posts: 16
I don't really understand what you really want, there is nothing wrong in casting an instance since the object itself IS an instance of the specified class. I think what you mean is polymorphism.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley