Article View: borland.public.jbuilder.java.language
Article #20135Simple sub-menu question?
From: Eric Advincula
Date: Sun, 26 Oct 1997 00:00
Date: Sun, 26 Oct 1997 00:00
156 lines
4188 bytes
4188 bytes
--------------4E57087818C0E421FE47608C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Can someone look at this code and tell me what needs to be done to add
an addActionListener
for the following sub-menu:
In an ordinary menu its easy:
Menu menuHelp;
MenuItem menuAbout;
MenuBar menuBarMain;
.
.
.
menuHelp = new Menu( "Help" );
menuAbout = new MenuItem( "About..." );
menuHelp.add( menuAbout );
menuAbout.addActionListener( this );
menuBarMain.add( menuHelp );
.
.
.
if (event.getSource() == menuAbout ) {
aboutDlg.show();
}
/*******************************************/
But for sub-menus its a little different:
Menu menuFile, subMenuOpen;
MenuItem menuExit, menuSchedule;
MenuBar menuBarMain;
.
.
.
menuFile = new Menu( "File" );
.
.
.
// File -> Open sub-menu selection
1) subMenuOpen = new Menu( "Open" );
// File -> Open -> Phone Listing sub-menu selection
2) subMenuOpen.add( new MenuItem( "Phone Listing..." ));
3) menuFile.add( subMenuOpen );
// File -> Open -> Schedule sub-menu selection
4) subMenuOpen.add( new MenuItem( "Schedule..." ));
5) menuFile.add( subMenuOpen );
menuFile.addSeparator(); // Separator between menu items
// File -> Exit menu selection
menuExit = new MenuItem( "Exit" );
menuExit.addActionListener( this );
menuFile.add( menuExit );
menuBarMain.add( menuFile );
for numbers 1-5 how do you add an action listener when the names of the
submenus are the
same.
By the way I'm using 1.1 of the jdk
Thanks in advance for any help
--------------4E57087818C0E421FE47608C
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<HTML>
Can someone look at this code and tell me what needs to be done to add
an addActionListener
<BR>for the following sub-menu:
<P><B><U>In an ordinary menu its easy:</U></B>
<P>Menu menuHelp;
<BR>MenuItem menuAbout;
<P>MenuBar menuBarMain;
<BR> .
<BR> .
<BR> .
<BR>menuHelp = new Menu( "Help" );
<BR>menuAbout = new MenuItem( "About..." );
<BR>menuHelp.add( menuAbout );
<BR>menuAbout.addActionListener( this );
<BR>menuBarMain.add( menuHelp );
<BR> .
<BR> .
<BR> .
<BR>if (event.getSource() == menuAbout ) {
<BR> aboutDlg.show();
<BR>}
<BR>
<P>/*******************************************/
<P><B><U>But for sub-menus its a little different:</U></B>
<BR>
<P>Menu menuFile, subMenuOpen;
<BR>MenuItem menuExit, menuSchedule;
<P>MenuBar menuBarMain;
<BR> .
<BR> .
<BR> .
<BR>menuFile = new Menu( "File" );
<BR> .
<BR> .
<BR> .
<BR>// File -> Open sub-menu selection
<BR>1) subMenuOpen = new Menu( "Open" );
<P>// File -> Open -> Phone Listing sub-menu selection
<BR>2) subMenuOpen.add( new MenuItem( "Phone Listing..." ));
<BR>3) menuFile.add( subMenuOpen );
<P>// File -> Open -> Schedule sub-menu selection
<BR>4) subMenuOpen.add( new MenuItem( "Schedule..." ));
<BR>5) menuFile.add( subMenuOpen );
<P>menuFile.addSeparator(); // Separator between menu items
<P>// File -> Exit menu selection
<BR>menuExit = new MenuItem( "Exit" );
<BR>menuExit.addActionListener( this );
<BR>menuFile.add( menuExit );
<BR>
<P>menuBarMain.add( menuFile );
<P>for numbers 1-5 how do you add an action listener when the names of
the submenus are the
<BR>same.
<P>By the way I'm using 1.1 of the jdk
<P>Thanks in advance for any help
<BR> </HTML>
--------------4E57087818C0E421FE47608C--
Technical Details
Message-ID:
<34542DF3.8686E7C5@inreach.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,acfe0bdfac8d69a1,start X-Google-Attributes: gidf74b3,public From: Eric Advincula <rsystems@inreach.com> Subject: Simple sub-menu question? Date: 1997/10/26 Message-ID: <34542DF3.8686E7C5@inreach.com> X-Deja-AN: 285263194 Organization: STS/Ceridian Newsgroups: borland.public.jbuilder.java.language