To Create an object at runtime


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: To Create an object at runtime

  1. #1
    Huiyuanm Guest

    To Create an object at runtime


    IF I put the declaration of some components into the method of 'actionPerformed',for
    example,
    JTextArea ErrorMsg=new JTextArea(4,10);

    Why it doesn't work?

    Thank you!

  2. #2
    Paul Clapham Guest

    Re: To Create an object at runtime

    This makes ErrorMsg a local variable for that method. You can't refer to it
    outside the method, and as soon as the method finishes its local variables
    are candidates for garbage collection.

    Don't know what you mean by "it doesn't work". Local variables work.
    You'll get a compiler error if you try to reference them outside of their
    scope. Hope this helps, your question isn't very clear or specific.

    Huiyuanm <huiyuanm@uwyo.edu> wrote in message
    news:38d3b1ae$1@news.devx.com...
    >
    > IF I put the declaration of some components into the method of

    'actionPerformed',for
    > example,
    > JTextArea ErrorMsg=new JTextArea(4,10);
    >
    > Why it doesn't work?
    >
    > Thank you!




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center