Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > order of coding

Reply
Thread Tools

order of coding

 
 
-
Guest
Posts: n/a
 
      03-23-2005
what's the preferred way?

JMenuBar menuBar = new JMenuBar();

JMenu menu = new JMenu(...);
menuBar.add(menu);

JMenu menu1 = new JMenu(...);
menuBar.add(menu1);

OR

JMenu menu = new JMenu(...);
JMenu menu1 = new JMenu(...);

JMenuBar menuBar = new JMenuBar();

menuBar.add(menu);
menuBar.add(menu1);
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      03-23-2005
- <> wrote:
> what's the preferred way?
>
> JMenuBar menuBar = new JMenuBar();
>
> JMenu menu = new JMenu(...);
> menuBar.add(menu);
>
> JMenu menu1 = new JMenu(...);
> menuBar.add(menu1);
>
> OR
>
> JMenu menu = new JMenu(...);
> JMenu menu1 = new JMenu(...);
>
> JMenuBar menuBar = new JMenuBar();
>
> menuBar.add(menu);
> menuBar.add(menu1);


It's entirely up to you. If you insist on a guideline, it's generally
to minimize the average space (in lines) between the first and last use
of a variable. That seems to recommend the latter. If your menus are
very complicated the following is also nice, and ends up improving even
more:

private JMenuBar buildMenuBar()
{
JMenuBar menuBar = new JMenuBar();

menuBar.add(buildFileMenu());
menuBar.add(buildEditMenu());

return menuBar;
}

private JMenu buildFileMenu()
{
JMenu menu = new JMenu("File");

...

return menu;
}

...

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
Marcin Grunwald
Guest
Posts: n/a
 
      03-23-2005
- wrote:

> what's the preferred way?
>
> JMenuBar menuBar = new JMenuBar();
>
> JMenu menu = new JMenu(...);
> menuBar.add(menu);
>
> JMenu menu1 = new JMenu(...);
> menuBar.add(menu1);
>
> OR
>
> JMenu menu = new JMenu(...);
> JMenu menu1 = new JMenu(...);
>
> JMenuBar menuBar = new JMenuBar();
>
> menuBar.add(menu);
> menuBar.add(menu1);


I prefere:

JMenuBar menuBar = new JMenuBar();
createMenu(menuBar);
createMenu1(menuBar);

private JMenu createMenu(JMenuBar menuBar) {
JMenu menu = new JMenu(...);
...
menuBar.add(menu);
return menu;
}

private JMenu createMenu1(JMenuBar menuBar) {
JMenu menu = new JMenu(...);
...
menuBar.add(menu);
return menu;
}

--
Cheers
grundig
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PEP 8: Byte Order Mark (BOM) vs coding cookie twyk Python 2 08-25-2008 03:59 AM
Opinions on include order and coding standards Adrian C++ 13 03-31-2008 12:56 PM
general coding issues - coding style... calmar Python 11 02-21-2006 10:36 AM
If you get an order # does it mean the order is accepted? =?Utf-8?B?U3RldmUxMDc3?= Windows 64bit 3 05-12-2005 11:46 PM
Traversion order cf. output order in XSL Soren Kuula XML 2 02-01-2004 09:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57