Article View: borland.public.jbuilder.java.language
Article #14440Re: How to call a component by name?
From: David Sykes
Date: Thu, 09 Sep 1999 00:00
Date: Thu, 09 Sep 1999 00:00
41 lines
1590 bytes
1590 bytes
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:
<7r7l9d$1et3@forums.borland.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>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,43efad4802ffae21 X-Google-Attributes: gidf74b3,public From: "David Sykes" <SykesD@edvc.com> Subject: Re: How to call a component by name? Date: 1999/09/09 Message-ID: <7r7l9d$1et3@forums.borland.com> X-Deja-AN: 522842262 References: <7r3sre$st7@forums.borland.com> <7r525b$8nj7@forums.borland.com> <7r6i1e$m6p1@forums.borland.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.language