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

Question from JExam

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question from Jexam..
Select the statement which most closely describes the user interface of an applet with the following init() method:
public void init(){
Panel p = new Panel();
p.setLayout(new BorderLayout());
p.add(new Button("Hello"), BorderLayout.EAST);
p.add(new Button("Bye"), BorderLayout.WEST);
add(p);
}

##ans1##
Two buttons are displayed. A button with "Hello" is on the right side of the applet. The button with "Bye" is on the left side of the applet. Both buttons extend from the centre of the applet to each side, and are the height of the applet.
##ans2##
Two buttons are displayed. A button with "Hello" is on the right side of the applet. The button with "Bye" is on the left side of the applet. Both buttons are only as wide as the text on the button, but are the height of the applet.
##ans3##
Two buttons are displayed. A button with "Hello" is on the right side of the applet. The button with "Bye" is on the left side of the applet. Both buttons are only large enough to support the associated button texts.
The answer is given as 2.
But i think the answer should be 2. sinec the default layout of an applet is FlowLayout, and in FlowLayout , the components are given their preferred width and preferred height, when u add an panel to it it occupies only the north region of the applet. it will occupy the entire applet. so, when u add buttons to this panel, they would be only large enough to accomodate their button text's.
Please correct me if i am wrong
Thank U.
Mary.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mary,
The panels layout is specifically set to Borderlayout eventhough its default is FlowLayout.
p.setLayout(new BorderLayout());

The Buttons added to East and West in a Border Layout always honors the preferred width but not the height.
Correct answer is 2.
HTH,
Sai Priya.
 
Sai Priya
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mary,
The panels layout is specifically set to Borderlayout eventhough its default is FlowLayout.
p.setLayout(new BorderLayout());

The Buttons added to East and West in a Border Layout always honors the preferred width but not the height.
Correct answer is 2.
HTH,
Sai Priya.
 
Mary Robert
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry, in my previous post i said the ans should be 2 , but it should be 3. I tried to run the code and the applet was displaying two buttons in the north portion with the buttons large enough to accomodate their text's. so, the answer should be 3 not 2.
Thank U
Mary.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mary,
Yes, I agree with you. The correct answer is 3. Because we are placing a borderLayout into a flowLayout (default of applet). The borderLayout only has the height of the center to figure out. Therefore its preferred height is that of the buttons! That being the case, the flowLayout will place them centered in the top part of the applet.
I also compiled and ran the example to prove my point!
Great job,
Manfred.
 
Sai Priya
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got shocked checking the answer after compiling it!
Thanks Manfred.
Sorry Mary!
reply
    Bookmark Topic Watch Topic
  • New Topic