Re: [NetBeans]changing menuitems
- From: Daniel Moyne <daniel.moyne@xxxxxxx>
- Date: Sat, 26 Jul 2008 16:54:02 +0200
RedGrittyBrick wrote:
Daniel Moyne wrote:GenListView.getInstance().disableMenuItem(GenListView.getInstance().menuItem1);
I am using Netbeans and in my class "GenListView" where most of the code
is created by Netbeans I have menu items members with private status
which means that oustide of any instances of "GenListView" NO WAY to
simply change any of those menu items like desabling enabling them.
As I want to do this from a class that I will call hereafter "Other" not
included in GenListView this is what I did :
(a) in class "GenListView" I added this :
- in some methods :
menuItem1=jMenuItem1; //jMenuItem is declared as private by NetBeans
instance = this;
- these 2 methods :
public static GenListView getInstance() {
return instance;
}
public void enableMenuItem(JMenuItem menuItem) {
menuItem.setEnabled(true);
}
- these members :
static public GenListView instance;
public JMenuItem menuItem1;
(b) in class "Other" I added this :
- in some method :
Sorry what do you mean here ?
GenListView must be a singleton?
if so why not make a static method enableMenuItem(SomeClass someID,This is an idea
boolean enabled)?
Rather than telling GenListView what to do, maybe you should look at itok this is a very interesting approach but how to implement a Listener in
the other way around and provide methods that allow you to tell
GenListView about some external event, then let GenListView decide on
appropriate changes to it's display.
I think you may need to disentangle your View from your Controller.
Maybe have GenListView implement a Listener (of some sort) and register
itself as a listener to whatever class is changing the state that
requires menu items to be disabled? Maybe Actions would help too?
GenListView that would intercept call from any other instances ?
Now a more general question : when using NetBeans you get help from the gui
to basically fabricate all graphic components but now when you have to
develop your own code is it possible and realistic to install it in the
same class.
I will have a look at the 2 websites you suggest.
Thanks.
It works but looks complex to me ; any way to make it simpler as there is
no possibility for direct access of "jMenuItem1" from other class ?
Regards.
Elsewhere, Karsten Lentzsch recently suggested Fowlers essay. I think it
might be useful in this context too.
http://martinfowler.com/eaaDev/OrganizingPresentations.html
I'd also read more about well-known design patterns and consider whether
Interfaces, Enums etc would help.
http://en.wikipedia.org/wiki/Design_Patterns#Behavioral_patterns
.
- Follow-Ups:
- Re: [NetBeans]changing menuitems
- From: thufir
- Re: [NetBeans]changing menuitems
- References:
- [NetBeans]changing menuitems
- From: Daniel Moyne
- Re: [NetBeans]changing menuitems
- From: RedGrittyBrick
- [NetBeans]changing menuitems
- Prev by Date: Re: where is the java preferences file located
- Next by Date: Re: [NetBeans]changing menuitems
- Previous by thread: Re: [NetBeans]changing menuitems
- Next by thread: Re: [NetBeans]changing menuitems
- Index(es):
Relevant Pages
|