Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question about MenuBar and Frame?

 
michael wang
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only Frames can contain menu bars or pull-down menus?
true or false
i think it true.
but the answer is false
so pls give me a explanation.
thanks
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You forgot about subclassing!
All subclasses of Frame will also allow a menu bar and menus.
When reading these type of questions, look out for words like 'only' or 'all'
By the way, the question seems flawed? There is no such things as 'Frames' in java, but there is a class Frame, just my beef
 
Stephen Batsas
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers,
You can also attach a JMenuBar to a JApplet. I have done it. Check the API.
Regards,
Stephen Batsas
SCJP2
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct me if I am wrong, but the JMenuBar belongs to the Swing package which the SCJP2 Exam does not cover.
Other then what Stephen has said, under the AWT framework only Frame based classes can have a menubar?
[ March 04, 2002: Message edited by: Rajinder Yadav ]
 
Matt Ghiold
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might seem silly, but possible if you wanted, you can also make a frame, then make a window and give ownership of the window to the frame you just created, and that window can support a menubar. So, without subclassing (which is perfectly viable), you can still have 2 classes that support a menubar.
Correct?
-Matt
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Giving ownership of a window to a frame still doesn't change the fact that you're dealing with a Frame... the frame object now owns the windows object
Originally posted by Matt Ghiold:
This might seem silly, but possible if you wanted, you can also make a frame, then make a window and give ownership of the window to the frame you just created, and that window can support a menubar. So, without subclassing (which is perfectly viable), you can still have 2 classes that support a menubar.
Correct?
-Matt
 
Matt Ghiold
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Giving ownership of a window to a frame still doesn't change the fact that you're dealing with a Frame... the frame object now owns the windows object

Yes, this is true, but the window would own the menubar =).
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you don't quite understand the concept of ownership, sorry to put it that way
Question, can you add a menu bar to a window object before making it a property of a frame? If the answer is no then windows can't have menu bars can they!
Owned in this context means the windows object is controlled by the frame, for all practical purpose they are one in the same!
Or maybe it's just me?
Just in case you are wondering, here it is straight out of the JDK, "A Window object is a top-level window with no borders and no menubar."
Originally posted by Matt Ghiold:

Yes, this is true, but the window would own the menubar =).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic