Hi All, I came across a review question in the Khalid's book, the answer of which I feel is not correct. The question goes like this: Which of these methods can be used to manipulate the bounds of a Component object? Select all valid answers. (a) setSize() (b) setDimnesions() (c) setBounds() (d) setLocation() (e) setPosition() Answers: a,c,d I agree with 'a' and 'c' but not with 'd'. How can location be used to manipulate the bounds ? Am I wrong or is the answer wrong? Can anybody clear this for me. Thanks in advance. Kezia.
public void setSize(int width, int height) Resizes this component so that it has width width and height. public void setSize(Dimension d) Resizes this component so that it has width d.width and height d.height. public void setBounds(int x, int y, int width, int height) Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height. public void setBounds(Rectangle r) Moves and resizes this component to conform to the new bounding rectangle r. This component's new position is specified by r.x and r.y, and its new size is specified by r.width and r.height public void setLocation(int x, int y) Moves this component to a new location. The top-left corner of the new location is specified by the x and y parameters in the coordinate space of this component's parent. public void setLocation(Point p) Moves this component to a new location. The top-left corner of the new location is specified by point p. Point p is given in the parent's coordinate space. I base my argument on setBounds by name saying it changes bounds of a component, it has a variant accepting first two parameters x and y, which change location of a component. With this view setLocation also changes the location i.e. x and y coordinates of the component and so should be seen as changing the bounds of an object. Cheers, Manoj
I think a,c ,d are correct as bound take into consideration size as well as location, by setting the location we are affecting the bounds of the object.
------------------ Muhammad Farooq Sun Certified Programmer for Java 2 Platform
Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Joined: May 19, 2001
public Rectangle getBounds() Gets the bounds of this component in the form of a Rectangle object. The bounds specify this component's width, height, and location relative to its parent.
According to the definition of getbounds(), we come to know that bounds of a component is in the form of a rectangle, which is inturn determined by the width and height of the component. If you move a component with a definite width and height to another location, the width or height does not change; the component with the same width and height is moved to a different location. How can moving the component in this way be used to manipulate the bounds of the component? This is what I am not clear about. Regards, Kezia.
subject: Location and bounds of a component object