• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Jxam question on Frame and menubar

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True or False
Only Frames can contain menu bars or pull-down menus.
The answer is false. But I choose true and also I read somewhere that only Frames can contain menubars. Could anyone please explain me which is correct.
Thanks in advance.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frame is not the only component that can have menu bars...
Especially if you look into Java Swing.
Here is an excerpt from Java Cram by Bill Brogden:
"Adding menus to an aplication requires a class that implements
the MenuContainer interface. The classes in the java.awt package
that implement MenuContainer are Component, Frame, Menu,
and MenuBar, so practically anything can host a menu."

Regards,
Khalid
[This message has been edited by Khalid Bou-Rabee (edited July 14, 2000).]
 
Khalid Bou-Rabee
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry for posting the same thing twice.
I'm having Browser problems...
Khalid
[This message has been edited by Khalid Bou-Rabee (edited July 14, 2000).]
 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Frame is not the only component that can have menu bars...
Especially if you look int Java Swing.
Here is an excerpt from Java Cram by Bill Brogden:
"Adding menus to an aplication requires a class that implements
the MenuContainer interface. The classes in the java.awt package
that implement MenuContainer are Component, Frame, Menu,
and MenuBar, so practically anything can host a menu."

Regards,
Khalid


Hi Khalid,
I think Frame is the only component which have function like :
public void setMenuBar(MenuBar mb)
so first portion of the question is 100% correct to me. yes there is a problem here when we think about pull downs menu. i think or i should say i am sure there is a method in component class where u can add pull down menu to component. i am trying to remember the name of method. i don't have API at home. today i am working from home.
so because of pull down menu the answer is false.

Oh! i got it.
public synchronized void add(PopupMenu popup)
Adds the specified popup menu to the component.

any comment java expert.
vivek

[This message has been edited by Vivek Shrivastava (edited July 14, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi kalid,
That is a valid explanation. Thanks you so much.
 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi java expert,
Here i am looking forward to find any comment on my logic(poted above). i just wanna know whather i am right or worng?
Please someone help me.
vivek
 
Khalid Bou-Rabee
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surya, glad I was of some help.
Now, Vivek, java.awt.Frame, java.awt.Window, java.applet.Applet and java.awt.Panel can have both menu bars and pop-up menus attached to them. They all (either directly or indirectly) implement the MenuContainer interface and are thus are related to the class Component.
Hope this makes it clearer,
Khalid (Java Expert? not yet)
[This message has been edited by Khalid Bou-Rabee (edited July 14, 2000).]
 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi khalid,
may be i am stupid so that i can't understand or i am missing something here.
As far as PopupMenu is concerned i do agree with u that we can add popupmenu to apple,window,frame and panel classes. because all these classes have following method :

public synchronized void add(PopupMenu popup)
Inherited from Component class.
Now we should talk about menubar. i know there is a method in Frame class
public void setMenuBar(MenuBar mb)
U can use this method to add menubar to a frame. but i am not aware of any method in Applet,Window and Panel classes that can be use to add a menubar to them. if u are aware of any method or way to add menubar to applet,panel or window. please do let me know.
i would realy appreciate if u could provide a simple java code here. i am really confused.
waiting for your reply.
vivek


PS: Java Expert Maha,Tony,ajith,Herbert and so many please help here. really looking forward to hear from u guys. please let me know what am i missing?.
 
Khalid Bou-Rabee
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right, the other containers do not provide functions for
setting the Menu Bars. Potentially, however, you are able to
code menu bars into the other components through creating a class
that will add the Menu Bar capabilities (Just as Frame does to
the Window Class).
Regards,
Khalid
 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi khalid,
Thanks for making me clear.



You are right, the other containers do not provide functions for
setting the Menu Bars. Potentially, however, you are able to
code menu bars into the other components through creating a class
that will add the Menu Bar capabilities (Just as Frame does to
the Window Class).
Regards,
Khalid


The way u are talking about is differnet thing but there is no direct way to add menubar to panel,applet and window.

thanks
vivek
 
Khalid Bou-Rabee
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems that adding a MenuBar to a Component is not possible unless you actually add your code to the package...
Here is a Window with a Menu Bar supposedly added to it. This code does not compile correctly because the MenuBar.parent property is friendly and cannot be accessed outside of the package... hmm... It seems adding menubars to components may be possible but strenuous.
Then again, I have a rather narrow view on this subject. Management??
--- Code: AddMenuBar.java ---
//Does not compile, MenuBar.parent cannot be
// accessed outside of package

<pre>
import java.awt.*;
import java.io.*;
public class MenuBarAdd {
java.awt.Window myWindow;
MenuBar menuBar;
MenuBarAdd() {
//instantiate Window
myWindow = new Window();
//instantiate menuBar
menuBar = new MenuBar();
//Add an item to menu
Menu myMenu = new Menu("hey");
myMenu.add(new MenuItem("woho!"));
myMenu.add(new MenuItem("woho! 2"));

menuBar.add( myMenu);
//set parent of menuBar as myWindow
menuBar.parent = myWindow;
//make myWindow appear...
myWindow.setBounds(100,100,200,200);
myWindow.setVisible(true);

//make sure everything is alright to save sanity...
myWindow.invalidate();
}

public static void main() {
MenuBarAdd mba = new MenuBarAdd();
}
}
</pre>

[This message has been edited by Khalid Bou-Rabee (edited July 14, 2000).]
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
'Only Frames can contain menu bars or pull-down menus '
The answer is false. The mere reason is the 'or pull-down menus ' part. If the answer WOULD HAVE BEEN just the first portion of the given answer 'Only Frames can contain menu bars' , then the answer will be 'true'. Menubar can be added to only Frame objects. And as <a href="http://java.sun.com/products/jdk/1.2/docs/api/java/awt/Component.html#method_summary<BR rel="nofollow">">here in Java API the Component class had an add(PopupMenu) method, any object which happened to be a Component can have 'PopupMenu' added to it. Since the given answer says 'only frames can have PopupMenu' , the answer is false.
This 'any Component can have PopupMenu attached to it' feature of Java can be used to make an elegant PopupMenu appear when we click on a Component. For example if there is an appln which has many components on the screen, and when you right-click on an object, a beautiful PopupMenu can be made to appear with MenuItems like 'Copy' , 'Paste', 'Cut' etc. It all in our hands how we make use of this feature by programming intelligently.
regds
maha anna
 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks maha,
I am totally agree with u and that is what i was trying to say but i think i could not. thanks making everything clear here.

regards
vivek
 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic