Which region is used by default when a Component is added to
Which region is used by default when a Component is added to a BorderLayout?
A) NORTH
B) CENTER
C) WEST
D) LEFT
52.
The class GridLayout constructs ___________ to hold components.
A) a horizontal grid with one row
B) a vertical grid with one column
C) a grid with multiple rows and columns
D) a square grid with the same number of rows as columns
53.
When components are added to a container with a GridLayout, the component:
A) fills the next spot in the row, continuing in the first position of the next row if the current row is full.
B) fills the next spot in the column, continuing in the first position of the next column if the column is full.
C) fills in row x, column y if x and y are two integers passed to the Container method add.
D) fills in a random empty position in the grid.
54.
The fact that class Graphics is abstract contributes to Java’s portability because:
A) drawing is performed differently on every platform that supports Java. A subclass of Graphics must be created that uses the drawing capabilities of the current platform.
B) objects of non-abstract classes can only be instantiated on the Windows platform.
C) drawing should not be performed on non-Linux platforms.
D) Class Graphics is not abstract.
55.
Which of the following statements about the Graphics object is true?
A. The Graphics object is an argument to class Component’s repaint method.
B. The Graphics object is instantiated by the user.
C. The Graphics object is the argument to a lightweight GUI component\'s paintComponent method.
D. The Graphics class is abstract.
E. The Graphics object manages a graphics context.
A) A, C, E.
B) C, D, E.
C) A, B, D, E.
D) All are true.
56.
Which of the following are valid Java statements?
A. Color c = new Color( 0, 255, 0 );
B. Color c = new Color( 0.0f, 1.0f, 0.0f );
C. Color c = new Color( 0.0d, 1.0d, 0.0d );
D. setGreen( c.getGreen() - 2 );
A) All of the above.
B) A, B, C.
C) A, B, D.
D) A, B.
57.
The JColorChooser dialog allows colors to be chosen by all but which of the following?
A) Swatches
B) Hue, saturation, brightness
C) Gradient, cycle, brightness
D) Red, Green, Blue
58.
Method getFont of class Graphics returns:
A) the current font name as a string.
B) the font size in points.
C) a Graphics object representing the current font.
D) a Font object representing the current font.
59.
The Java statement: g.fillOval( 290, 100, 90, 55 );
A) Draws a filled oval with its center at coordinates x=290, y=100, with height=90 and width=55.
B) Draws a filled oval with its left most point at coordinates x=290, y=100, with height=90 and width=55.
C) Draws a filled oval bounded by a rectangle with its upper left corner at coordinates x=290, y=100, with width=90 and height=55.
D) Draws a filled oval bounded by a rectangle with its upper left corner at coordinates x=290, y=100, with height=90 and width=55.
60.
Which of the following statements draws an arc that sweeps from the top of an oval to the left-most edge?
A) g.drawArc( 200, 100, 100, 50, 90, 90 );
B) g.drawArc( 100, 200, 50, 100, 90, 180 );
C) g.drawArc( 100, 200, 50, 100, 180, 90 );
D) g.drawArc( 200, 100, 100, 50, 180, 90 );
61.
Which of the following statements about the Java 2D API is true?
A) A Graphics2D object is instantiated to draw Java 2D figures.
B) Class Graphics2D is a subclass of class Graphics.
C) To access Graphics2D capabilities, cast the Graphics reference passed to paintComponent to a Graphics2D reference.
D) All of the above are true.
62.
The Graphics2D method(s) that determine(s) the color and texture for the shape to display is/are:
A) setStroke
B) setPaint
C) setTexture and setColor
D) setTexturePaint
63.
Arrow keys can manipulate a JSlider object. Which of the following statements does not correctly describe how the arrow keys are used?
A) The left-arrow and right arrow keys decrease or increase (respectively) the thumb of the JSlider by 1.
B) The down-arrow and up-arrow keys decrease or increase (respectively) the thumb of the JSlider by 1.
C) The PgDn and PgUp keys decrease or increase (respectively) by block increments of one-tenth of the range of values.
D) The Home key and End key move the thumb to the maximum or minimum (respectively) value of the JSlider.
64.
JSliders generate what type of event?
A) ActionEvents
B) ChangeEvents
C) WindowEvents
D) MouseEvents
65.
What happens if setSize is not called on a window?
A) The window is displayed at its preferred size.
B) It is a syntax error.
C) The window is not displayed.
D) Only the title bar appears.
Solution
51.
Ans. A) NORTH.
A border layout lays out a container to fit its components in 5 regions, NORTH, SOUTH, EAST, WEST, and CENTER. Each region may contain one or more than one component. By default, the NORTH region is used while adding a component in border layout.
52.
Ans. C) A grid with multiple rows and columns
A GridLayout class lays out the container’s components in a rectangular grid. One component cane be placed in each rectangle. Rectangular grid formed by the GridLayout class can contain any number of rows and columns.
53.
Ans. A) Fills the next spot in the row, continuing in the first position of the next row if the current row is full.
Components are added in the GridLayout one after the other. The components are added row wise. When one row is full then the components are added starting from the first position of the next row.
54.
Ans. A) Drawing is performed differently on every platform that supports Java. A subclass of Graphics must be created that uses the drawing capabilities of the current platform.
The objects of non-abstract classes are instantiated on the windows platform. But graphics is an abstract class not a non-abstract class.
Hence, option (B) is incorrect.
Drawing can be allowed in non-Linux platforms such as openSolaris and FreeBSD.
Hence, option (C) is incorrect.
Graphics is an abstract class.
Hence, option (D) is incorrect.
Graphics class is an abstract that contributes to java’s portability because: drawing is performed differently on every platform that supports java.
Hence, the correct answer is option (A).
55.
Ans. B) C, D, E
Repaint() method in Java is invoked with arguments to define the region that requires updating. It does not require Graphic Object as the argument.
Hence, Option A) is false.
Graphic objects are instantiated by the AWT. Users cannot instantiate the graphic object since it is an abstract class.
Hence. Option B) is false.
Paint() method in Java, uses the graphic object to set the properties of the components like foreground property.
Hence, Option C) is true.
The Graphics class is abstract so that components using the Graphics class can provide a custom concrete implementation of it that is specific to the component and in cases even platform-specific.
Hence, Option D) is true.
A graphic context enables drawing on the screen. Graphic object manages graphic context to draw the objects on the screen.
Hence, Option E) is true.
56.
Ans. D) A, B
The values of RGB (Red, Green, and Blue) must be in the range of 0 to 255. Therefore, its values can be 0 in between 0 to 255.
Color c = new Color (0,255,0) and Color c = new Color (0.0f, 1.0f, 0.0f) are correct.
Hence, the correct answer is option (D).
57.
Ans. C) Gradient, Cycle, Brightness
JColorChooser dialog allows users to choose from a palette of colors. It provides Swatches, HSB (Hue, Saturation and Brightness) and RGB (Red, Green and Blue) colors. But it doesn’t provide an option to choose Gradient, Cycle and Brightness.
Hence, the correct answer is option (C).
58.
Ans. D) A font object representing the current font.
getFont of class Graphics returns the current font represented by font object.
Hence, the correct answer is option (D).
59.
Ans. C) Draws a filled oval bounded by a rectangle with its upper left corner at coordinates x=290, y=100, with width=90 and height=55.
The parameters of g.fillOval() are
Int x: left edge of the rectangle.
Int y: Top edge of the rectangle
Int width: Width of the rectangle
Int height: Height of the rectangle.
The method is invoked as g.fillOval(int x, int y, int width, int height). This denotes the sequence of the parameters in the method.
Hence, Option C) is correct.
60.
Ans. A) g.drawArc( 200, 100, 100, 50, 90, 90 );
The parameters in g.drawArc are X- coordinate, Y-coordinate, width, height, start angle and arc angle. Therefore, the values of g.drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) should be g.drawArc (200, 100, 100, 50, 90, 90) in order to draw an arc that sweeps from the top of an oval to the left-most edge.
Hence, the correct answer is option (A).
61.
Ans. C) To access Graphics2D capabilities, cast the Graphics reference passed to paintComponent to a Graphics2D reference.
Graphics objects returned by API which are higher than java 1.2 will only be the subclass of Graphics2D not all Graphics2D’s are subclasses of Graphics.
Hence, option (B) is incorrect.
To access the Graphics2D capabilities, cast the Graphics reference passed to paintComponent to a Graphics2D reference.
Hence, the correct answer is option (C).
62.
Ans. B) setPaint
setPaint() method is used in Java to colour and texture the shape.
Hence, Option B) is correct.
63.
Ans. D) The Home key and End key move the thumb to the maximum or minimum (respectively) value of the JSlider.
Arrow keys manipulates the Jslider object just like they manipulate the normal word template. The up and down keys are used to increase and decrease the thumb of the Jslider by 1. The left and right keys are used to increase and decrease the thumb of the Jslider object by 1. The PgDn and PgUp keys decrease or increase (respectively) by block increments of one-tenth of the range of values.
Hence, the correct Option is D).
64.
Ans. B) ChangeEvents
Jslider uses only one ChangeEvent per slider since the event’s only state is the source property.
65.
Ans. D) Only the title bar appears
setSize sets the size of the window. If not called then the full will not appear.





