Sun Java Solaris Communities My SDN Account Join SDN
 
Quizzes

Quiz: The Swing Tutorial

 

Quizzes Index

Test your knowledge! This quiz covers some lesser known facts that GUI programmers are likely to need while developing and distributing programs that use Swing components. Choose the best answer for each question, then click Submit to see how you scored.

Note: The text of The Swing Tutorial will soon cover all these topics, but currently some are only used in code samples or mentioned in API tables. For example, the JFrame page has not yet been updated to cover setDefaultLookAndFeelDecorated, but its examples and API tables have. You can find the source code for each example both through the pages that discuss the example and from the example index. You can search for particular topics using the Tutorial Search box in the right column of The Java Tutorial's front page.

1. How do you get Java Web Start?
 A. You get it automatically when you download the J2SE 1.4.1 JRE.
 B. You get it automatically when you download the J2SE 1.4.1 SDK.
 C. You have to download it separately, such as from the Java Web Start download page.
 D. A and B.


2. Which of the following lines of code makes a label display text with the fonts shown in this screenshot:

 A. label = new JLabel("<html>The <em>last</em> word is <font color=red>red</font>.</html>");
 B. someLabel.setFont("<html>The <em>last</em> word is <font color=red>red</font>.</html>");
 C. someLabel.setText("<html>The <em>last</em> word is <font color=red>red</font>.</html>");
 D. A and C.
 E. A, B, and C.


3. Which of the following lines of code makes a JLabel's text display over multiple lines?
 A. label.setText("multiple\nlines");
 B. label.setText("multiple\rlines");
 C. label.setText("<html>multiple<br>lines");
 D. All of the above.


4. Which of the following does JComponent establish to support key bindings?
 A. An input map for keys that a component handles when the component or one that it contains has the focus.
 B. An input map for keys that a component handles only when the component itself has the focus.
 C. An input map for keys that a component handles when the component's window either has the focus or contains the component that has the focus.
 D. All of the above.


5. When was the new focus subsystem (which, among other things, provides centralized focus management with java.awt.KeyboardFocusManager) added?
 A. 1.4
 B. 1.3
 C. 1.2
 D. 1.1


6. How can a program detect when a JFrame's size has changed?
 A. By registering a component listener on the JFrame.
 B. By registering a container listener on the JFrame.
 C. By registering a window listener on the JFrame.
 D. B and C.


7. Assuming the Java look and feel is used, which of the following code snippets creates/shows a frame or dialog that uses the decorations provided by the Java look and feel (rather than by the native window system)? Note: All the code snippets compile.
 A. JFrame f = new JFrame();
f.setDefaultLookAndFeelDecorated(true);
 B. JFrame.setDefaultLookAndFeelDecorated(true);
JFrame f = new JFrame();
 C. JFrame.setDefaultLookAndFeelDecorated(true);
JOptionPane.showMessageDialog(f, "A message");
 D. All of the above.


8. Consider the following code. What can you say about the button and menu item it creates?
  public class AnAction extends AbstractAction {
      public AnAction() {
          super(someText);
          putValue(SHORT_DESCRIPTION, otherText);
          putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_M));
      }
      . . .
  }
  . . .
  JButton b = new JButton();
  JMenuItem mi = new JMenuItem();
  Action anAction = new AnAction();
  b.setAction(anAction);
  mi.setAction(anAction);

 A. They both have AnAction as an action listener.
 B. They both display the text specified by someText.
 C. They both have a tool tip with the text specified by otherText.
 D. The button looks pressed when the user presses (in the Java look and feel) Alt-M.
 E. The menu item fires an action event when the menu item is visible and the user presses the M key.
 F. All of the above.


9. Consider this code, which uses the AnAction class shown in question 8. What can you say about the button and menu item it creates?
  JButton b = new JButton();
  JMenuItem mi = new JMenuItem();
  Action anAction = new AnAction();
  b.setAction(anAction);
  mi.setAction(anAction);
  b.setText("blue");
  anAction.putValue(Action.NAME, "red");

 A. The final value of the button's text property is "blue".
 B. The final value of the button's text property is "red".
 C. The final value of the menu item's text property is "red".
 D. B and C.


10. How can you download the source code and other files required for the examples in The Swing Tutorial? (Note: The Swing Tutorial is part of The Java Tutorial.)
 A. Using your browser, download each file pointed to by the relevant example index.
 B. Download the zip file for The Java Tutorial.
 C. Download just the Swing part of The Java Tutorial.
 D. Download all the examples in The Java Tutorial.
 E. All of the above.