Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32195
| From | Nigel Wade <nmw@ion.le.ac.uk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How to access properties of a class from another class? |
| Date | 2015-07-29 15:24 +0100 |
| Message-ID | <d1s61sFbabhU1@mid.individual.net> (permalink) |
| References | <mp8m3g$dk2$1@speranza.aioe.org> |
On 28/07/15 20:45, 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.) Two weeks is barely enough to begin to climb the learning curve. It isn't true that NetBeans likes to cram everything into a single file. NetBeans does what you tell it to. If that's the way you design your GUI then that's what NetBeans will do. But it's not the only way to do it. You can build your GUI from multiple smaller elements, each within its own class. You can then build these smaller elements into a larger GUI. Whether NetBeans can actually manipulate your smaller elements within the matisse GUI design tool depends on how much effort you put into correctly designing the smaller elements. If they can be imported as Beans then matisse will use them. Even if your smaller GUI elements cannot be imported as Beans, and manipulated by matisse, it doesn't preclude you from utilizing them in your main GUI. You will, however, have to create them yourself and embed them into the design using the code section of the component properties or add the relevant code, normally just after the init_components() method has been invoked. > > To practice MVC schema, it is necessary to design separate control class and view class. 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. Eric has already explained how to change this. Whether you want to do that is another matter. I have only very, very occasionally modified the access of a matisse generated component. > (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. NetBeans makes this operation fairly trivial. The key-binding (at least on Linux) Alt-Insert (alternatively the menu Source->Insert code...) brings up a popup menu where you can select what type of code you want to insert. This includes getters and setters,. From the dialog displayed select which private elements you want NetBeans to construct the getters/setters for and then let NetBeans do the boiler plating.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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