• 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

SCJP ques on AWT

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Button okButton = new Button("ok");
public void init()
{
setLayout(new BorderLayout());
add("South", okButton);
add("North", okButton);
add("East", okButton);
add("West", okButton);
add("Center", okButton);
setSize(300,300);
}
the above displays only one button in center, why is it so??
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because no Button has been specifically allocated any area that is NORTH, SOUTH, EAST , WEST or CENTER and the default is CENTER
Wali
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kanan
Look carefully at code
only one object of button is created before init()
that means we can add only one button on our layout
no matter how many add statements are there
Another point to be aware of is that it takes
the latest position of the component to be placed
just try it by shifting add("Center", okButton);
to the first line
I hope it helps
Gaurav
reply
    Bookmark Topic Watch Topic
  • New Topic