• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SWT code not using a receiving object

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i am running this example in eclipse and it works fine, but i'm baffled by the strucuture of a particular statement:

Please notice that the:

"createMenuBar();" statement below does not have a receiving object, for example something like: "Menu m = createMenuBar(); and notice that the createMenuBar() funtion is returning a "Menu", but there isn't a Menu object on the receiving end!? , is this a new 5.0 feature by any chance?

<code>
public Shell open(Display display) {
shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
e.doit = closeAddressBook();
}
});

createMenuBar(); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

..........

}

private Menu createMenuBar() { <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Menu menuBar = new Menu(shell, SWT.BAR);
shell.setMenuBar(menuBar);

// create each header and subMenu for the menuBar
createFileMenu(menuBar);
createEditMenu(menuBar);
createSearchMenu(menuBar);
createHelpMenu(menuBar);

return menuBar;
}

</code>
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Obviously you can return the Menu object, and not do anything with it.
There are quite a lot of methods which have a return type one doesn't use, particularly boolean returns, in the J2SE API (not that I can remember the name of one offhand): does this mean it is a general rule that a return value can be ignored???

CR
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried a little app with methods in which return an Exception, an ArrayList, a "C" from the thread about protected methods and inheritance from today's Java(advanced) forum, a primitive value (a double) and a JWindow; all of them can return their values without anything being done with it, eg
not necessarily in that order. It seems to compile and run quite happily.

CR
[ April 19, 2006: Message edited by: Campbell Ritchie ]
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Campbell!

Also Campbell, if you've had a chance to use SWT and Swing, which would you prefer to use on your next project?

I heard from a coworker that SWT is somewhat easier to use than Swing and faster as well!

Thanks again Campbell!
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only too pleased to help. I have never used SWT, so don't know.

Anybody else?
 
Oh the stink of it! Smell my tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic