Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. Getting an applet's components returns null

Getting an applet's components returns null

Scheduled Pinned Locked Moved Java
data-structuresquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rareseu
    wrote on last edited by
    #1

    Hy guys ! i'm trying to make an array with the components of my applet like this : instancing :

    public Component\[\] componente=new Component\[100\];
    /\*\* Initializes the applet tester \*/
    @Override
    public void init() {
        try {
            componente=this.getComponents();
            ...
    }//init
    

    and displaying in a textArea :

        for (int i=0;i
    

    the result i get is :

    componente :
    0 null

    my applet however has plenty of componenets, does anybody know why this might happen ?

    F 1 Reply Last reply
    0
    • R rareseu

      Hy guys ! i'm trying to make an array with the components of my applet like this : instancing :

      public Component\[\] componente=new Component\[100\];
      /\*\* Initializes the applet tester \*/
      @Override
      public void init() {
          try {
              componente=this.getComponents();
              ...
      }//init
      

      and displaying in a textArea :

          for (int i=0;i
      

      the result i get is :

      componente :
      0 null

      my applet however has plenty of componenets, does anybody know why this might happen ?

      F Offline
      F Offline
      fly904
      wrote on last edited by
      #2

      The reason it returns null is because the componants havent been initialized by the time init() is called. Solution: Don't call componente=this.getComponents(); from within init. Have a look at this[^] for an explanation.

      My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

      R 1 Reply Last reply
      0
      • F fly904

        The reason it returns null is because the componants havent been initialized by the time init() is called. Solution: Don't call componente=this.getComponents(); from within init. Have a look at this[^] for an explanation.

        My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

        R Offline
        R Offline
        rareseu
        wrote on last edited by
        #3

        I suspected that was it, i made my gui using netbeans IDE and it generates an initComponents method , and even tho i used getComponents inside this method afetr it instances the componenets i still get null :|

        F 1 Reply Last reply
        0
        • R rareseu

          I suspected that was it, i made my gui using netbeans IDE and it generates an initComponents method , and even tho i used getComponents inside this method afetr it instances the componenets i still get null :|

          F Offline
          F Offline
          fly904
          wrote on last edited by
          #4

          I presume you have something like this: public GUIView(SingleFrameApplication app) { super(app); initComponents(); //TRY IT HERE } Personally I hate NetBeans and normally write it all by hand. This is for a JFrame Application, apologies.

          My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

          modified on Saturday, May 9, 2009 12:29 PM

          R 1 Reply Last reply
          0
          • F fly904

            I presume you have something like this: public GUIView(SingleFrameApplication app) { super(app); initComponents(); //TRY IT HERE } Personally I hate NetBeans and normally write it all by hand. This is for a JFrame Application, apologies.

            My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

            modified on Saturday, May 9, 2009 12:29 PM

            R Offline
            R Offline
            rareseu
            wrote on last edited by
            #5

            i really don't have a choice aside from working with netbeans sice my deadline is close and it could never be done in time if i learned how to do it by hand the call is like this :

            public void init() {
            try {
            initComponents();// added by netbeans, uneditbale(have to trick it into adding code here)
            initMyComponents();//added by me, but didn't work
            } catch (Exception ex) {
            ex.printStackTrace();
            }
            }//init

            is there any other way to tell when the initialization is over, or when initComponenets is done executing?

            F 1 Reply Last reply
            0
            • R rareseu

              i really don't have a choice aside from working with netbeans sice my deadline is close and it could never be done in time if i learned how to do it by hand the call is like this :

              public void init() {
              try {
              initComponents();// added by netbeans, uneditbale(have to trick it into adding code here)
              initMyComponents();//added by me, but didn't work
              } catch (Exception ex) {
              ex.printStackTrace();
              }
              }//init

              is there any other way to tell when the initialization is over, or when initComponenets is done executing?

              F Offline
              F Offline
              fly904
              wrote on last edited by
              #6

              Try this:

              @Override
              public void start()
              {
                  //TRY HERE
              }
              

              I haven't used Applets in years, I'm a bit rusty.

              My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

              R 1 Reply Last reply
              0
              • F fly904

                Try this:

                @Override
                public void start()
                {
                    //TRY HERE
                }
                

                I haven't used Applets in years, I'm a bit rusty.

                My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

                R Offline
                R Offline
                rareseu
                wrote on last edited by
                #7

                tried that :| , even inside the paint method , nothing works :| btw thanks for all your time fly904 :)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups