P2 Test Questions

(Project Test Home Page)

# Question
1 To create a Window in a Java Application that is compatible with JDK 1.1 (AWT) you can extend what class(es)?
(Choose all that apply)

A. javax.swing.JFrame
B. java.awt.Window
C. javax.swing.JWindow
D. None of the above

2 Assuming that "objAppFrame" is an object of a class that extends the Frame class, which statements is true about the following code sample?
(Choose all that apply)

objAppFrame.setSize( 500, 100);

A. Create a window that is 500 pixels tall and 100 pixels wide.
B. Create a window that starts 500 pixels from the top of the screen.
C. Create a window that starts 100 pixels from the left of the screen.
D. None of the above.

3 To enable the "X" button on the title bar of a Java Application to close the Java window you must add which listener to the frame component?
(Choose one)

A. Frame listener
B. Window listener
C. DOS listener
D. None of the above

4 Assuming that this code will compile, what will the following code display?
(Choose all that apply)

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MyHello_App_Frame extends java.awt.Frame {

  public void paint(java.awt.Graphics g) {
     g.drawString("Hello World",100,50);
  }
  public static void main( String args [] ) { 
    MyHello_App_Frame objAppFrame = new MyHello_App_Frame();

    objAppFrame.setTitle( "Java Application extending java.awt.Frame");
    objAppFrame.setSize( 500, 100); 
    objAppFrame.setVisible( true ); 
  } //main()
}

A.  Will display Hello World to the Java Console
B.  Will display a blank window which is 500 x 100
C.  Will display Hello World to a Java Application window which is 500 x 100.
D.  None of the above

5 drawString()
drawString() is a method in which class?
(Choose one)

A.  java.awt.Graphics
B.  java.Window
C.  java.awt.Window
D. None of the above

6 drawString()
If the size of the application is set to 100 x 100, which of the following code samples will compile?
(Choose all that apply)

A. drawString("Hello World");
B. drawString("Hello World", 50, 50);
C. drawString("Hello World", 200, 200);
D. None of the above.

7 setVisible()
Assuming that "objAppFrame" is an object of a class that extends the Frame class, which statements is true about the following sample code?
(Choose all that apply)

objAppFrame.setVisible( true );

A. The setVisible() method was inherited from the Component class.
B. The above statement will not compile because true needs to be in quotes.
C. The Frame component will become visible on the computer screen.
D. None of the above.

8 x & y Coordinates of the Java window
Which of the following statements is true about the Java window?
(Choose all that apply)

A. The "x" coordinates go from left to right.
B. The "y" coordinates go from top to bottom.
C. Position (0,0) is in the bottom left corner of the Java window.
D. None of the above

9 getInsets() of the Container class
Which of the following statements is true about the getInsets() method of the Container class and the Insets class.

A. getInsets() returns an Insets object.
B. insets.left & insets.top will determine the upper-left corner location of displayable area.
C. Is used to determine where the Java window is placed inside the computer screen.
D. None of the above.
10 setTitle()
Assuming that "objAppFrame" is an object of a class that extends the Frame class, which statements is true about the following sample code?
(Choose all that apply)

objAppFrame.setTitle( "Hello World" );

A. Hello World will display as a content title inside of the java window.
B. Hello World will display in the title bar of the java window.
C. Hello World will display in the status bar of the java window.
D. None of the above.