Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #32184

Re: How to access properties of a class from another class?

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Jeff Higgins <jeff@invalid.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How to access properties of a class from another class?
Date Tue, 28 Jul 2015 16:59:04 -0400
Organization A noiseless patient Spider
Lines 53
Message-ID <mp8qk9$49v$1@dont-email.me> (permalink)
References <mp8m3g$dk2$1@speranza.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=gbk; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 28 Jul 2015 21:02:01 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="8e164d158183579609bf09837dee5210"; logging-data="4415"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Vr/64203KP3wlZYeyCwgJvVrlya1uJgU="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0
In-Reply-To <mp8m3g$dk2$1@speranza.aioe.org>
Cancel-Lock sha1:ygwPCvxDMKWdRu2BAj5HIBFTEUs=
Xref csiph.com comp.lang.java.programmer:32184

Show key headers only | View raw


On 07/28/2015 03:45 PM, Xue Feng wrote:
> Hi,
>
> Beg your pardon for this silly question.I am familiar with the concept
> of encapsulation indeed. However, for some problems, I think there must
> be better solutions.
>
> My question comes from a feature of Netbeans which is well-known for its
> wonderful GUI design facilities. However, for all GUI components,
> Netbeans likes to cram them into a single source file of the main frame.
> A direct result for this is all code pertain to definition of GUI
> component objects and event handling are concentrated in a source file,
> and it meants to flate rapidly. For large-scale projects, this is not a
> good idea.(I have only little experience with Netbeans for two weeks.
> There mybe other options I don't know. Tell me please.)
>
> To practice MVC schema, it is necessary to design separate control class
> and view class.

The reason you use a GUI builder is to free yourself from having to deal
with the architecture of the GUI model and concentrate on your problem
domain.
Let it do its job.

> Both of them have occasions to interact with GUI
> components. However, all of components are defined in the main frame
> class as private members. Therefore, control class and view class need
> to access these components encapsulated in the main frame class. I think
> there mybe some ways to achieve the goal as follows:
>
> (1) Define control class and veiw class as inner class of the main frame
> class. But, this practice will result in a huge souce file obviously.
> (2) Define components as public members. However, it seems that Netbeans
> does not allow this way.
> (3) Define many 'get' methods for the main frame class, and invoke them
> from  control class and view class to get references of component
> needed. This is an ordinary pratice, but somewhat tedious. Moreover, it
> also lacks flexibility especially when the GUI design changes frequently.
> (4) Take some language construct such as friend class from C++. I don't
> konw whether Java has this kind of construct.
> (5) Is there any way to dynamically generate an object at runtime in
> terms of the main frame class as template? This object wraps up all
> components' reference as its public member. Then, pass the object to
> control object and view object. Maybe reflection can help, but I am not
> sure about it.
>
> For the above specific situation, I wonder whether there are ways to
> circument encasulation to make programming more convenient and flexibiable.

Yes, ditch the GUI builder and build it all yourself.


Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to access properties of a class from another class? Xue Feng <xf.lotus@yahoo.com> - 2015-07-29 03:45 +0800
  Re: How to access properties of a class from another class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-28 16:58 -0400
  Re: How to access properties of a class from another class? Jeff Higgins <jeff@invalid.invalid> - 2015-07-28 16:59 -0400
  Re: How to access properties of a class from another class? Nigel Wade <nmw@ion.le.ac.uk> - 2015-07-29 15:24 +0100
    Re: How to access properties of a class from another class? Xue Feng <xf.lotus@yahoo.com> - 2015-08-01 16:10 +0800

csiph-web