aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes some queries pl! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "some queries pl!" Watch "some queries pl!" New topic

some queries pl!

ashok khetan
Ranch Hand

Joined: Jul 29, 2001
Posts: 153
hi all! here are some queries. pl try to solve these!
[1]why does the following code not exit when run? for coming out, u need to press Ctrl C.
import java.awt.*;
public class MyClass {
public static void main(String args[]) {
TextArea ta = new TextArea();
[2]True or False:
A given MouseEvent CANNOT be dispatched to both MouseMotionListener and MouseListener objects that have registered with the screen component.
[3]True or False:Only Frames can contain menu bars or pull-down menus.
[4]What is the target in an Event?
A. The Object() where the event came from.
B. The Object() where the event is destined for.
C. What the Object() that generated the event was doing.
[5] The following will add a Component 'comp' to a container 'c', if it's layout is governed by GridLayout 'g'?
** can u pl explain the above method? it's from some mock-exam..i didn't get it.
[6] Can u pl tell what does the statement at //3 actually do(in a general way)?
import java.awt.*;
public class TestClass extends Frame
Button b = new Button("OK");
TestClass( )
add("South", b);
this.setSize(400, 400); //1
b.setVisible(true); //2)
this.getLayout().layoutContainer(this); //3
this.setVisible(true); //4
public static void main(String[] args)
new TestClass();
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Hi ashok,
really dificult questions. Real exam is much simpler!!!
[3]True or False:Only Frames can contain menu bars or pull-down menus.
THINK True. Applets dont has, Dialog dont has, Panel dont has.
There is a method with this name in api-doc. But you add the specified component to the layout. Can't see any container.
[6] this.getLayout().layoutContainer(this); //3
The line does does not change anything.
getLayout() --> get Object of Type LayoutManager.
Should be the default Layout Manager of Frame, because you did not specify any.
Object_LayoutManager.layoutContainer(this) --> set Container Frame as layout Container.
Frame was allready the Container.
Correct me if i am wrong
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
Hi both,
[1] I think (but I'm not sure) that since you use an AWT component, the GUI thread will be started and the main thread will only stop when the GUI thread stops.
Anyone comment on this please
[2] What is a screen component ??? Anyway ! If you have a MouseEvent object you can use it for both MouseListeners and/or MouseMotionListeners, I don't see why you could not ! Answer is False.
[3] True, only Frames may contain menu bars or pull-down menus ! setMenuBar only exists in the class Frame.
[4] I think the answer is B, the target is the Object to which the event is destined in other words the EventListener that registered with the event source to receive that kind of Event.
[5] The answer is true, since the question says that there is a container whose layout is governed by the GridLayout which is a LayoutManager. So adding some component to a LayoutManager owned by a container will effectively add the component to the container but after the LayoutManager has layed out all added components. Jana Griscti has good notes on this at the following address
[6] Frame is a container, so by executing line 3 it tells its LayoutManager that now it's the time to lay the components out and display them. So this.getLayout() will return the LayoutManager of the Frame (in this case an instance of BorderLayout) and then invoking layoutContainer(this) upon the instance of the layout will pass this container (i.e. the Frame) to the LayoutManager and lay it out so that the component (the button) will be displayed according to the BorderLayout policies !
If you feel something is not clear, let me know

[Blog] [Blogroll] [My Reviews] My Linked In
I agree. Here's the link:
subject: some queries pl!