Article View: borland.public.jbuilder.java.language
Article #14443Re: How to call a component by name?
From: Kobus du Toit
Date: Thu, 09 Sep 1999 00:00
Date: Thu, 09 Sep 1999 00:00
50 lines
1988 bytes
1988 bytes
An example in the real world.
One of my friends is going to use that functionality to create a general object
model. Then the program can be changed without much coding, (after alot of
coding :) )
Kobus
David Sykes wrote:
> One advantage is parameterization.
>
> MyClass getInstance( String className ) {
> return Class.forName( className ).newInstance();
> }
>
> className can be read from a .properties file, for example :-).
>
> David Sykes
> edv consulting
>
> <nlaan> wrote in message news:7r6i1e$m6p1@forums.borland.com...
> > What are the advantages of using:
> > MyClass myClass = Class.forName("MyClass").newInstance();
> >
> > as opposed to:
> > MClass myClass = new MyClass();
> >
> > thanks;
> > nlaan
> >
> >
> > Johan Forsberg wrote in message <7r525b$8nj7@forums.borland.com>...
> > >
> > >Bombi <abonetti@yahoo.com> skrev i
> > >diskussionsgruppsmeddelandet:7r3sre$st7@forums.borland.com...
> > >> Hi there,
> > >>
> > >> I've an application with a JPanel. How can I use my JPanel calling it
> by
> > >> name ?
> > >>
> > >> Something like JPanel1 jPanel = createComponent("JPanel1") instead
> of
> > >> new JPanel1() ?
> > >
> > >JPanel1 jPanel=Class.forName("my.package.JPanel1").newInstance();
> > >
> > >
> >
> >
Technical Details
Message-ID:
<37D77D1D.B09EFC2D@iname.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7r3sre$st7@forums.borland.com> <7r525b$8nj7@forums.borland.com> <7r6i1e$m6p1@forums.borland.com> <7r7l9d$1et3@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,43efad4802ffae21 X-Google-Attributes: gidf74b3,public From: Kobus du Toit <battlezone@iname.com> Subject: Re: How to call a component by name? Date: 1999/09/09 Message-ID: <37D77D1D.B09EFC2D@iname.com> X-Deja-AN: 522876907 Content-Transfer-Encoding: 7bit References: <7r3sre$st7@forums.borland.com> <7r525b$8nj7@forums.borland.com> <7r6i1e$m6p1@forums.borland.com> <7r7l9d$1et3@forums.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Reply-To: battlezone@iname.com Newsgroups: borland.public.jbuilder.java.language