Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQ+:Question ID :954959231549

 
Rahul Ramachandran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following will add a Component 'comp' to a container 'c', if it's layout is governed by GridLayout 'g'?
1) c.add(comp);
2) c.add("Center", comp);
3) g.add(comp);
4) g.addLayoutComponent("Component Name", comp);
5) c.add(comp,-1);
The correct answers are given as 1,4 and 5.
I felt 2) should also be among the correct answers.
(I am quoting the Java API documentation)(look at (e))
a)Component add(Component comp)
Adds the specified component to the end of this container.
b)Component add(Component comp, int index)
Adds the specified component to this container at the given position.
c)void add(Component comp, Object constraints)
Adds the specified component to the end of this container.
d)void add(Component comp, Object constraints, int index)
Adds the specified component to this container with the specified constraints at the specified index.
e)Component add(String name, Component comp)
Adds the specified component to this container.
 
jeena jose
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following code working fine.
i feel answer is 1,2,4,5.
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]) {
CompLay cl = new CompLay(); }
CompLay() {
Panel p = new Panel();
p.setLayout(new GridLayout());
p.add("Center",new Button("One"));
add("South",p);
setSize(300,300);
setVisible(true);
}}
Panel p = new Panel();
p.setLayout(new GridLayout());
p.setBackground(Color.pink);
p.add("Center",new Button("One"));
add("South",p);
setSize(300,300);
setVisible(true);
}}
 
jeena jose
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following code working fine.
i feel answer is 1,2,4,5.
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]) {
CompLay cl = new CompLay(); }
CompLay() {
Panel p = new Panel();
p.setLayout(new GridLayout());
p.add("Center",new Button("One"));
add("South",p);
setSize(300,300);
setVisible(true);
}}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic