STMicroelectronics Java Questions: AWT Windows Graphics and FontsTab.amp
Download PDF of This Page (Size: 119K) ↧
Examrace Placement Series prepares you for the toughest placement exams to top companies.
-
The code below draws a line. What color is the line? g setColor (Color. Red. Green. Yellow. Red. Cyan); g drawLine (0, 0, 100, 100); Which is correct? Red Green Yellow Cyan Black Ans: d
-
What does the following code draw? g setColor (Color. Black); g drawLine (10, 10, 10, 50); g setColor (Color. RED); g drawRect (100, 100, 150, 150)
-
Explain the code? A red vertical line that is 40 pixels long and a red square with sides of 150 pixels A black vertical line that is 40 pixels long and a red square with sides of 150 pixels A black vertical line that is 50 pixels long and a red square with sides of 150 pixels A red vertical line that is 50 pixels long and a red square with sides of 150 pixels A black vertical line that is 40 pixels long and a red square with sides of 100 pixel Ans: b
-
Which of the statements below are true?
-
A polyline is always filled.
-
A polyline can not be filled.
-
A polygon is always filled.
-
A polygon is always closed
-
A polygon may be filled or not filled
Ans: b, d and e
-
-
What code would you use to construct a 24-point bold serif font? new Font (Font. SERIF, 24, Font. BOLD); new Font ( “SERIF” 24, “BOLD” ); new Font ( “BOLD” 24, Font. SERIF); new Font ( “SERIF” Font. BOLD, 24); new Font (Font. SERIF, “BOLD” 24); Ans: d
-
What does the following paint () method draw? Public void paint (Graphics g) { g. DrawString ( “question #6” 10, 0); } The string “question #6” with its top-left corner at 10, 0 A little squiggle coming down from the top of the component, a little way in from the left edge Ans: b
-
What does the following paint () method draw? Public void paint (Graphics g) { g. DrawString ( “question #6” 10, 0); } A circle at (100, 100) with radius of 44 A circle at (100, 44) with radius of 100 A circle at (100, 44) with radius of 44 The code does not compile Ans: d
-
What is relationship between the Canvas class and the Graphics class? Ans: A Canvas object provides access to a Graphics object via its paint () method. What are the Component subclasses that support painting. Ans: The Canvas, Frame, Panel and Applet classes support painting.
-
What is the difference between the paint () and repaint () method? Ans: The paint () method supports painting via a Graphics object. The repaint () method is used to cause paint () to be invoked by the AWT painting method.
-
What is the difference between the Font and FontMetrics classes? Ans: The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.
-
Which of the following are passed as an argument to the paint () method? A Canvas object A Graphics object An Image object A paint object Ans: b
-
Which of the following methods are invoked by the AWT to support paint and repaint operations? paint () repaint () draw () redraw () Ans: a
-
Which of the following classes have a paint () method? Canvas Image Frame Graphics Ans: a and c
-
Which of the following are methods of the Graphics class? drawRect () drawImage () drawPoint () drawString () Ans: a, b and d
-
Which Font attributes are available through the FontMetrics class? ascent leading case height Ans: a, b and d
-
Which of the following are true? The AWT automatically causes a window to be repainted when a portion of a window has been minimized and then maximized. The AWT automatically causes a window to be repainted when a portion of a window has been covered and then uncovered. The AWT automatically causes a window to be repainted when application data is changed. The AWT does not support repainting operations. Ans: a and b
-
Which method is used to size a graphics object to fit the current size of the window? Ans: GetSize () method.
-
What are the methods to be used to set foreground and background colors? Ans: SetForeground () and setBackground () methods.
-
You have created a simple Frame and overridden the paint method as follows public void paint (Graphics g) { g. DrawString ( “Dolly” 50, 10); } What will be the result when you attempt to compile and run the program?
-
The string “Dolly” will be displayed at the centre of the frame
-
An error at compilation complaining at the signature of the paint method
-
The lower part of the word Dolly will be seen at the top of the form, with the top hidden.
-
The string “Dolly” will be shown at the bottom of the form
Ans: c
-
-
Where g is a graphics instance what will the following code draw on the screen. g fillArc (45, 90, 50, 50, 90, 180)
-
An arc bounded by a box of height 45, width 90 with a centre point of 50, 50, starting at an angle of 90 degrees traversing through 180 degrees counter clockwise.
-
An arc bounded by a box of height 50, width 50, with a centre point of 45, 90 starting at an angle of 90 degrees traversing through 180 degrees clockwise.
-
An arc bounded by a box of height 50, width 50, with a top left at coordinates of 45, 90, starting at 90 degrees and traversing through 180 degrees counter clockwise.
-
An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded by a
box of height 50, width 50 with a centre point of 90, 180.
Ans: c
-
-
Given the following code import java. Awt. *; public class SetF extends Frame { public static void main (String argv[]) { SetF s = new SetF (); s. SetSize (300, 200); s. SetVisible (true); }} How could you set the frame surface color to pink
-
s setBackground (Color. Pink)
-
s setColor (PINK)
-
s Background (pink)
-
s color = Color. Pink
Ans: a
-
-
How would you set the color of a graphics context called g to cyan?
g setColor (Color. Cyan).
g setCurrentColor (cyan).
g setColor ( “Color. Cyan” ).
g setColor ( “cyan” ).
g setColor (new Color (cyan) ).
Ans: a