Swing - Basic

Print the objectives

Take the exam   Take a beta test

This exam requires the ability to create a main window, with a menu and a toolbar; a dialog box with basic controls: label, input field, list, combo, check box, radio button and "Ok" button.
This covers similar knowledge to the free on-line Swing tutorial http://java.sun.com/docs/books/tutorial/uiswing/, parts:

  • Learning Swing by Example (except images)
  • How to Use Menus (the first basic part)
  • How to Use Tool Bars (the first basic part)
  • Basic ActionListeners and Basic Layout management

This exam is about Swing, not about AWT. For example, the knowledge of the AWT Button class is not required, while the Swing JButton class is part of the objectives. However, some AWT facilities used by a Swing application are expected to be known; as for example, the Component class that JButton (indirectly) extends.
Please remember that heavy (AWT, SWT) and light (Swing) components should not be mixed in the same UI.
Key shortcuts, enable/disable and renderers are excluded from this exam. Only simple handlers are included.

This exam assumes the prerequisite knowledge of some Java SE notions, at their basic level:

  • anonymous inner classes
  • multi-threading, Runnable (Ref How to Use Threads in The Java Tutorial).
  • basic event-driven programming

1 ONLINE RESOURCES

1. Java 2 SE API @ http://java.sun.com/j2se/1.5.0/docs/api/
2. Swing Tutorial @ http://java.sun.com/docs/books/tutorial/uiswing/index.html
3. Java Look and Feel Design Guidelines @ http://java.sun.com/products/jlf/
4. The Swing Connection @ http://java.sun.com/products/jfc/tsc/

5. SwingLabs @ http://www.swinglabs.org/projects.jsp
6. JGoodies @ http://www.jgoodies.com
7. NetBeans Platform @ http://www.netbeans.org/products/platform/
8. JavaDesktop Community @ http://community.java.net/javadesktop/
9. ClientJava @ http://www.clientjava.com/blog
10. Romain Guy's Blog @ http://jroller.com/page/gfx

2 BOOKS

1. Swing Tutorial
2. Swing Hacks
3. Swing 2nd Edition
4. Desktop Java Live
  Released  Beta  Frozen  

Event Thread and Queue  2 questions

  • Explain the difference between the application thread (executing the main method), and the GUI thread EventDispatchThread.
  • Implement a clean finish with threading (all threads are naturally done). It is different from forcing exit.
  • Use SwingUtilities.invokeLater(Runnable r) to create the main JFrame and its swing components from the EventDispatchThread, instead of the application thread.
Not covered: multi-threading with long operations and non trivial use of invokeLater, SwingWorker, other methods from SwingUtilities.
6 37 11

Window and Dialog  3 questions

  • Create a main window with the JFrame class.
  • Use the following methods (from JFrame and its hierarchy): getContentPane(), JFrame(String), setVisible(boolean), pack().
  • Given a behaviour, identify the appropriate constant for the setDefaultCloseOperation(int) method: DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE.
  • Create dialogs with JDialog and JOptionPane.
  • Explain how a dialog depends on a (main) frame.
  • List dialogs modalities, layout and elements, and the different ways they can be invoked.
Ref for Java 6 modalities: http://blogs.sun.com/roller/page/praveenm?entry=awt_modality_enhancements_in_java

Not covered: other types of frames, applets, windows

12 64 16

Panel  1 question

  • Explain the composite nature of a UI, including the Container class ability to contain other Components.
  • Write code that groups components within a JPanel.

Not covered: JXXXPane, borders, custom painting.

6 23 8

LayoutManager and Look and Feel  3 questions

  • Describe the layout manager mechanism and the basic usage of those: FlowLayout, BorderLayout.
  • Identify the default layout manager for each container included in this exam.
  • Associate a layout manager to a container.
  • Know the standard Looks and Feels, how to set them and identify them.

Not cover: other types of Layout Managers, other Look and Feel related topics.

13 25 26

Label  1 question

  • Create a simple JLabel to display text.
  • Use basic html tags to format the label text.
  • Use Icons in JLabels.

Not covered: fonts

6 26 8

Button  2 questions

  • Create a simple JButton.
  • Get/set the horizontal/vertical text position.
  • Use Icons in JButtons.
  • Write simple code that executes when the button is pressed (via an ActionListener).
Not covered: advanced use of ActionListeners.
4 15 16

Menu  1 question

  • Create menus, sub-menus and menu items.
  • Use JSeparator to separate menu items.
  • Put a menu bar in a JFrame.
  • Use the keyboard alternatives: mnemonics and accelerators.
  • Answer to an ActionEvent generated by a MenuItem.
Not covered: actions, pop-up menus.
2 10 11

Tool Bar  1 question

  • Create a toolbar and add it to a window.
  • Populate the toolbar with ImageIcon, JToolBar, JButton.
  • Add separators to a toolbar.
Specific JButton questions should stand in the Button category.
1 5 12

Text Field  1 question

  • Create a simple JTextField.
  • Set the text displayed by the field.
  • Get the data typed by the user.
Not covered: other text components, event handling.
4 6 11

Combo  1 question

  • Create a JComboBox, and populate it through its constructor.
  • Identify which element is selected, if any.
  • Use editable JComboBoxs for more flexibility.
Not covered: event handling, custom renderers.
3 14 4

Check Box  1 question

  • Create a JCheckBox with both text and icons.
  • Get and set its value (checked state) and label text.
Event handling is not covered.
5 9 2

Radio Button  1 question

  • Create a set of related JRadioButtons.
  • Get and set the selected button.
  • Get and set each button label text.
  • Use a ButtonGroup to group radio buttons.
Event handling is not covered.
8 3 5

List  1 question

  • Create a JList that let the user selects a single element.
  • Populate a JList via its constructor.
  • Use the DefaultListModel.
  • Identify which single element is selected.
  • Listen to selection changes.
Not covered: multiple element selection, custom ListModel, custom renderers.
2 23 8

Table  1 question

  • Create a JTable to present data to the user.
  • Populate a JTable via its constructor.
  • Associate a simple TableModel to a JTable.
  • Identify the selected row.
  • Listen to selection changes.
Not covered: custom editors, renderers, filters, sorters, selection modes.
3 25 12

Exam information

  • 26 minutes
  • 20 questions (510)
  • 75% required
  • +4 √
  • - 6  points
  • 15 day delay
  • status: released

Exam leader

Top contributors