Name:_______________________ Sample Exam Covers Chs 32-35 Multiple Choice Questions Only for This Test Part I: Questions: (1 pts each) 1 An event adapter can be implemented using ___________. A. standard adapter B. inner class adapter C. anonymous inner class adapter 2 The signature for the accessor method of a Date property birthDate should be __________. A. B. C. D. E. public java.util.Date birthDate() public java.util.Date getBirthDate() private java.util.Date birthDate() private java.util.Date getBirthDate() public java.util.Date getbirthDate() 3 The signature for the mutator method of a Date property birthDate should be __________. A. B. C. D. public void birthDate(java.util.Date date) public void setBirthDate(java.util.Date date) public void setbirthDate() public void birthDate() 4 An event and its corresponding listener is referred to as ____________. A. B. C. D. an an an an event event event event set class pair object 5 Which of the following is true? A. A bean must implement the java.io.Serializable interface to ensure a persistent state. B. A bean must be a public class. C. A bean must have a public no-arg constructor. D. A bean cannot have any constructors with parameters. 6 The signature for the accessor method of a Boolean property visible should be __________. A. public boolean visible() 1 B. C. D. E. public boolean getVisible() public static boolean isVisible() public boolean isVisible() private boolean isVisible() 7 Any event is an instance of _________. A. B. C. D. java.awt.ActionEvent javax.swing.JComponent java.awt.Component java.util.EventObject 8 5 Creating Custom Event Sets 10. Which of the followings are true? A. By convention, an event class should be named with suffix Event. B. An event class does not have a no-arg constructor, because you must always specify a source for the event when creating an event. C. A custom event class must extend java.util.EventObject or a subclass of java.util.EventObject. D. A custom event listener interface must extend java.util.EventListener or a subinterface of java.util.EventListener, and define the signature of the handlers. E. A listener interface for a custom event BeatEvent should be named BeanListener by convention. 9 Which of the following is true? A. Events can be unicasted (only one listener object is notified of the event). B. Events can be multicasted (each object in a list of listeners is notified of the event). C. The naming pattern for adding a multicast listener is "public void add<Event>Listener(<Event>Listener l)" D. The naming pattern for adding a unicast listener is "public void add<Event>Listener(<Event>Listener l) throws TooManyListenersException" E. A source component must have the appropriate registration and deregistration methods for adding and removing listeners. 10 The signature for the mutator method of a Date property birthDate should be __________. A. B. C. D. E. public public public public public void void void void void birthDate(java.util.Date date) setbirthDate() birthDate() setBirthDate(java.util.Date date) setBirthDate(java.util.Date date) 2 11 Any listener is an instance of _________. A. B. C. D. A. B. C. D. java.util.EventListener javax.swing.JComponent java.util.EventObject java.awt.ActionListener 12 The signature for the registration method for an ActionEvent should be __________. public public public public void void void void addActionListener(ActionEvent l) setAction(ActionListener l) setActionListener(ActionListener l) addActionListener(ActionListener l) 13 The size of a component in a container is determined by __________ A. the type of layout manager used by the container. B. certain properties common to all components (such as preferredSize, minimumSize, maximumSize, alignmentX, and alignmentY). C. the size of the container. D. the layout constraints associated with each component. 14 Which of the following properties are in JApplet? A. B. C. D. E. title contentPane resizable jMenuBar iconImage 15 ___________ is a Swing layout manager that arranges components on top of each other. A. B. C. D. E. BorderLayout BoxLayout CardLayout OverlayLayout GridLayout 16 Which of the following properties are in BorderLayout? A. B. C. D. E. alignment hgap layout vgap visible 17 Which of the following methods create an EtchedBorder? 3 A. B. C. D. BorderFactory.createEtchedBorder(Color.YELLOW, Color.RED) new EtchedBorder() new EtchedBorder(Color.YELLOW, Color.RED) BorderFactory.createEtchedBorder() 18 Which of the following properties are in JFrame? A. B. C. D. E. jMenuBar title iconImage resizable contentPane 19 Which of the following properties are in CardLayout? A. B. C. D. E. visible alignment vgap layout hgap 20 The preferredSize property is ignored in ______________. A. B. C. D. FlowLayout BorderLayout GridLayout Null layout 21 Which of the following are the valid methods in JTabbedPane? A. B. C. D. getToolTipTextAt(index) getTabCount() getTabPlacement() getTitleAt(index) 22 To use no layout manager in a container c, use _________. A. B. C. D. c.setLayout(NullLayout) c.setLayout(null) c.setLayout() c.setLayout(new NullLayout()) 23 Every layout manager is an instace of __________. A. B. C. D. the the the the 24 LayoutManager interface LayoutManager class Layout class Layout interface Which of the following methods create a LineBorder? A. new LineBorder() 4 B. C. D. E. BorderFactory.createLineBorder(Color.YELLOW) new LineBorder(Color.YELLOW, 3) new LineBorder(Color.YELLOW, 3, true) BorderFactory.createLineBorder(Color.YELLOW, 4) 25 Which of the following properties in java.awt.Component may effect layout? A. B. C. D. E. font background minimumSize maximumSize preferredSize 26 You can construct a JScrollPane using ____________. A. B. C. D. new new new new 27 A. B. C. D. E. A. B. C. D. E. JScrollPane(Component[]) JScrollPane(Component) JScrollPane() JScrollPane(Component, Component) __________ is a Swing layout manager that arranges components in a row or a column. GridLayout FlowLayout BorderLayout BoxLayout CardLayout 28 Which of the following properties are in CardLayout? hgap alignment visible layout vhap 29 How do you display a JPopupMenu? A. B. C. D. A. B. C. D. Add the JPopupMenu to a container. Invoke the setVisible(true) from a JPopupMenu. Invoke the show() from a JPopupMenu. Invoke the show(Component, x, y) from a JPopupMenu. 30 _____________ is the action that causes a popup menu to be displayed. Popup Popup Popup Popup trigger action reaction event 5 31 A JRadioButtonMenuItem is a subclass of ________. A. B. C. D. JMenuItem AbstractButton JMenu JComponent 32 A JCheckBoxMenuItem is a subclass of ________. A. B. C. D. AbstractButton JComponent JMenuItem JMenu 33 The method __________ places a menu item mi into a menu mu. A. B. C. D. mu.addMenuItem(mi) mu.add(mi) None of the above. mu.addItem(mi) 34 ___________ allows you to create custom buttons. A. A confirmation dialog B. An input dialog C. A message dialog D. An option dialog 35 ______________ displays a message that alerts the user and waits for the user to click the OK button to close the dialog. A. B. C. D. A message dialog An input dialog An option dialog A confirmation dialog 36 You can add a menu item into set an imageIcon property on ___________. A. B. C. D. a a a a JMenuItem JRadioButtonMenuItem JMenu JCheckBoxMenuItem 37 A MenuItem object can generate __________ events. A. B. C. D. ComponentEvent ActionEvent ItemEvent ContainerEvent 38 __________ is used to receive input from the user. 6 A. B. C. D. A. B. C. D. E. An option dialog A confirmation dialog A message dialog An input dialog 39 Which of the following statements are true? You You You You You 40 A. B. C. D. can can can can can How add a JMenu to a JPopupMenu. add a JMenuItem to a JPopupMenu. add a JPopupMenu to a JMenu. add a JCheckBoxMenuItem to a JPopupMenu. add a JRadioButtonMenuItem to a JPopupMenu. do you display a JPopupMenu? Invoke the show(Component, x, y) from a JPopupMenu. Add the JPopupMenu to a container. Invoke the setVisible(true) from a JPopupMenu. Invoke the show() from a JPopupMenu. 41 You can set an imageIcon property on ___________. A. B. C. D. a a a a JRadioButtonMenuItem JCheckBoxMenuItem JMenuItem JMenu 42 The method __________ places a menu mu into a menu bar mb. A. B. C. D. mb.addMenuItem(mu) mb.addItem(mu) mb.add(mu) None of the above. 43 The method __________ separates menu items in a menu mu. A. B. C. D. mu.add('-') None of the above. mu.addSeparator() Either a or b 44 A JRadioButtonMenuItem is a subclass of ________. A. B. C. D. AbstractButton JMenu JComponent JMenuItem 45 ____________ asks a question and requires the user to respond with an appropriate button. A. An input dialog B. A confirmation dialog C. An option dialog 7 D. A message dialog 46 Which of the following statements are true? A. JButton has an add method that enables you to add an instance of Action to the menu. B. JToolBar has an add method that enables you to add an instance of ActionListener to the menu. C. JButton has a constructor new JButton(Action) that enables you to add an instance of Action to the menu. D. JButton has an add method that enables you to add an instance of ActionListener to the menu. E. JToolBar has an add method that enables you to add an instance of Action to the menu. 47 A JMenu is a subclass of ________. A. B. C. D. A. B. C. D. JComponent AbstractButton JButton JMenuItem 48 ______________ displays a message that alerts the user and waits for the user to click the OK button to close the dialog. An input dialog A message dialog A confirmation dialog An option dialog Keys: 1. ABC 2. B 3. B 4. AC 5. ABC 6. D 7. D 8. ABCDE 9. ABCDE 10. E 11. A 12. D 13. ABCD 14. BD 15. D 16. BD 17. ABCD 8 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. ABCDE CE CD ABCD B A BCDE CDE BC D AE D A ABD ABC B D A ABCD B D BDE A ABCD C D ACD B CE ABD B 9