Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

a question about MenuBar and Frame?

 
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
 
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
 
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 ]
 
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 =).

 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic