| Author |
SWT code not using a receiving object
|
bob connolly
Ranch Hand
Joined: Mar 10, 2004
Posts: 204
|
|
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>
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
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
Joined: Mar 10, 2004
Posts: 204
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
Only too pleased to help. I have never used SWT, so don't know. Anybody else?
|
 |
 |
|
|
subject: SWT code not using a receiving object
|
|
|