Self Quiz 7

Given the following code:

public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D)g;
   g2.translate( getWidth()/2, getHeight()/2 );
   g2.rotate( 30 * Math.PI / 180 );
   g2.fillRect(0,0,200,200);
}

Which of the following describes the output?

Select one or more:

a. A filled black square that is 100-by-100 pixels in size.
b. The corner of the square is at the center of the component that is being painted, and the top side of the square descends at a 30 degree angle from that point. 
c. The rotate command rotates the picture by 30 degrees in a clockwise direction about the origin. 
d. The top of the square is rotated from the horizontal position onto a line that is 30 degrees clockwise of the horizontal. That line descends at a 30 degree angle. 

The correct answer is: The corner of the square is at the center of the component that is being painted, and the top side of the square descends at a 30 degree angle from that point., The rotate command rotates the picture by 30 degrees in a clockwise direction about the origin., The top of the square is rotated from the horizontal position onto a line that is 30 degrees clockwise of the horizontal. That line descends at a 30 degree angle.



Question 2

What does the following code do?

Action openAction = new AbstractAction( "Open..." ) {
   public void actionPerformed( ActionEvent e ) {
      doOpen();
   }
};

JButton openButton = new JButton( openAction );
 
JMenuItem openCommand = new JMenuItem( openAction );


Select one or more:

a. This code creates an Action that represents the opening of a file in the doOpen() instance method. 
b. This code creates a button from the Action. 
c. This code creates a menu item from the Action. 
d. This code reads a text file.

The correct answer is: This code creates an Action that represents the opening of a file in the doOpen() instance method., This code creates a button from the Action., This code creates a menu item from the Action.



Question 3

Which of the following code is correct to create an instance of ResourceBundle?

Select one:

a. ResourceBundle.getBundle();
b. ResourceBundle.getBundle(locale);
c. ResourceBundle.getBundle(resourcefilename); 
d. None of the above;

The correct answer is: ResourceBundle.getBundle(resourcefilename);



Question 4

Which of the following code displays the numbers with at least two digits before and after the decimal point?

a.
NumberFormat numberForm = NumberFormat.getNumberInstance();
DecimalFormat df = (DecimalFormat)numberForm;
df.applyPattern("00.00");

b.
NumberFormat numberForm = NumberFormat.getNumberInstance();
numberForm.setMaximumFractionDigits(2);
numberForm.setMinimumFractionDigits(2);

c.
NumberFormat numberForm = NumberFormat.getNumberInstance();
numberForm.setMaximumFractionDigits(2);

d.
a and b.

Select one:
a. Correct
b.
c.
d.

The correct answer is: a.



Question 5

How do you create a locale for the United States?

Select one:
a. new Locale("en", "US");
b. new Locale("US", "en");
c. Locale.US;
d. a and c; 

The correct answer is: a and c;



Question 6

Which statements about Preferences are true?

Select one or more:

a. Preferences are best saved in a file in the user’s home directory.
b. Preferences represent a snapshot of a program saved between sessions. 
c. To handle preferences, Java provides a class Preferences in the java.util.prefs package. 
d. Every time the program starts up, it reads the preferences, if any are available. Every time the program terminates, it saves the preferences. 

The correct answer is: Preferences represent a snapshot of a program saved between sessions., To handle preferences, Java provides a class Preferences in the java.util.prefs package., Every time the program starts up, it reads the preferences, if any are available. Every time the program terminates, it saves the preferences.



Question 7

To be a listener for ActionEvent, an object must be an instance of …

Select one:

a. ActionEvent
b. ActionListener 
c. EventObject
d. WindowListener
e. WindowEvent

The correct answer is: ActionListener



Question 8

Which of the following statements are true?

Select one or more:

a. Dialog boxes are defined by subclasses of the class JDialog. 
b. The main difference between JDialogs and JFrames is that a dialog box has a parent, which if closed, causes the dialog box to closes, too. 
c. When a modeless dialog is put up on the screen, the rest of the application is blocked until the dialog box is dismissed.
d. Modal dialog boxes are like independent windows, since they can stay on the screen while the user interacts with other windows.

The correct answer is: Dialog boxes are defined by subclasses of the class JDialog., The main difference between JDialogs and JFrames is that a dialog box has a parent, which if closed, causes the dialog box to closes, too.



No comments:

Post a Comment