You are on page 1of 5

Chapter13

AdvancedGUIApplications
.1

Test 1

Start With Q13


1.

Whatwillbetheresultsofexecutingthefollowingstatements?
x.setEditable(true);
x.setText(TinyTim);
(a)
(b)
(c)
(d)

ThetextfieldxwillhavethevalueTinyTimandbereadonly
ThetextfieldxwillhavethevalueTinyTimandtheuserwillbeabletochangeitsvalue
Thetextfieldxwillhavethevaluetrue
ThetextfieldxhavethevaluetrueTinyTim

Answer: B,ReadOnlyTextFields
2.

ThedefaultselectionmodeforaJListcomponentis
(a) Singleselection
(b) Singleintervalselection
(c) Multipleintervalselection
(d) Thereisnodefaultsetting
Answer: C,Lists

3.

WhenaniteminaJlistobjectisselecteditgeneratesa(n)
(a) Actionlistenerevent
(b) Actionperformedevent
(c) Listselectionlistenerevent
(d) Listselectionevent
Answer: D,Lists

4.

Todeterminewhichiteminalistiscurrentlyselecteduse
(a) ThegetSelectedIndexmethod
(b) ThegetSelectedValuemethod
(c) Both(a)and(b)
(d) Neither(a)or(b)
Answer: C,Lists

2GaddisStartingOutwithJava5:FromControlStructurestoObjects

5.

ToaddtheJListobjectaddressListtoascrollpanecalledscrollPane,usethefollowing
(a)
(b)
(c)
(d)

JScrollPanescrollPanenewJScrollPane(addressList);
scrollPane.add(addressList);
addressList.add(scrollPane);
addressList.addScrollPane(scrollPane);

Answer: A,Lists
6.

True/FalseBydefaultthescrollbarsarealwaysdisplayed.
Answer: False,Lists

7.

IfaddressListisaJListcomponent,whatwillthevalueofxbeafterthefollowingstatementis
executed:
xaddressList.getSelectedIndex();
(a)
(b)
(c)
(d)

Thevalueofthefirstselecteditem
Theindexofthefirstselecteditem
Anarrayofobjectscontainingtheitemsselected
Anarraycontainingtheindicesofalltheselecteditemsinthelist

Answer: B,Lists
8.

Whenaniteminthecomboboxisselected,thecomboboxexecutesitsactioneventlisteners
actionPerformedmethod,passing
(a) anItemEventobjectasanargurment
(b) aSelectionEventobjectasanargurment
(c) anActionEventobjectasanargument
(d) thecomboboxasanargument
Answer: C,ComboBoxes

9.

IfthecomboboxaddressBoxcontainsalistofstrings,whyisthereturnedvalueofgetSelectedItem
methodinthefollowingcodecasttoString?
StringselectedAddress;
selectedAddress(String)addressBox.getSelectedItem();
(a)
(b)
(c)
(d)

Thisisnotnecessary.
Becausethesyntaxofthemethodrequiresit.
Itmakestheprogrammorereadable
BecausethereturntypeofthemethodisanObject

Answer: D,ComboBoxes
10.

Ifauserentersavalueinthetextboxofaneditabletextboxandthevalueisnotinthelist,what
willthemethodgetSelectedIndexreturn?
(a) Theindexoftheitemthattheuserreplaced
(b) Theindexoftheitemtheuserentered
(c) 1
(d) 0,sincetheitemisnotinthelist
Answer: C,ComboBoxes

Chapter13AdvancedGUIApplications3

11.

TheImageIconclasssupportsallthefollowingfiletypes,except
(a) BMP
(b) JPEG
(c) GIF
(d) PNG
Answer: A,DisplayingImagesinLabelsandButtons

12.

True/FalseWhencreatingimages,theargumentpassedtotheimageparameterintheJLabel
constructorcanbeanImageIconobject,oranyobjectthatimplementstheIconinterface.
Answer: True,DisplayingImagesinLabelsandButtons

13.

Whatwilldisplaywhenthefollowingcodeisexecuted:
JLabellabelnewJLabel(Itisabeautifulday.);
labed.setIcon(SunnyFace.gif);
(a)
(b)
(c)
(d)

AlabelwiththetextItisabeautifulday.totheleftoftheSunnyFaceimage.
AlabelwiththetextItisabeautifulday.totherightoftheSunnyFaceimage.
AlabelwiththetextItisabeautifulday.belowtheSunnyFaceimage.
AlabelwiththetextItisabeautifulday.abovetheSunnyFaceimage.

Answer: B,DisplayingImagesinLabelsandButtons
14.

ToforcetheJFramethatenclosesawindowtoresizeitselfautomaticallywhenalargerobjectis
placedintheframe,usethe
(a) Thepackmethod
(b) Theresizemethod
(c) Thegrowmethod
(d) Theenlargemethod
Answer: A,DisplayingImagesinLabelsandButtons

15.

Amnemonicis
(a) Akeyonthekeyboardthatyoupresstoquicklyaccessacomponentsuchasabutton
(b) AkeyonthekeyboardthatyoupressincombinationwiththeSHIFTkeytoquicklyaccessa
componentsuchasabutton
(c) AkeyonthekeyboardthatyoupressincombinationwiththeALTkeytoquicklyaccessa
componentsuchasabutton
(d) AkeyonthekeyboardthatyoupressincombinationwiththeCTRLkeytoquicklyaccessa
componentsuchasabutton
Answer: C,MnemonicsandToolTips

16.

Toaddatooltiptoacomponentuse
(a) ThesetToolTipTextmethod
(b) TheaddToolTipTextmethod
(c) ThetoolTipTextmethod
(d) TheappendToolTipTextmethod
Answer: A,MnemonicsandToolTips

4GaddisStartingOutwithJava5:FromControlStructurestoObjects

17.

ThedefaultdirectoryfortheJFileChooserconstructoris
(a) YourlogindirectoryifyouareusingUNIX
(b) ProbablyMyDocumentsifyouareusingWindows
(c) Neither(a)or(b)
(d) Both(a)and(b)
Answer: D,FileChoosersandColorChoosers

18.

Whatwillhappenwhenthefollowingcodeisexecuted?
JPanelpanelnewJPanel();
ColorselectedColor;
JColorChoosercolorChoosernewJColorChooser();
selectedColorcolorChooser.showDialog(null,Selectcolor,Color.blue);
(a) AColorBoxwillbedisplayedintheupper,lefthandcornerofthescreenwithSelectcolorin
itsTitleBarandbluepreselected
(b) AColorBoxwillbedisplayedinthecenterofthescreenwithSelectcolorinitsTitleBarand
bluepreselected
(c) AColorBoxwillbedisplayedinthecenterofthescreenwithSelectcolorastheOKbuttons
textandbluepreselected
(d) AColorBoxwillbedisplayedinthelower,righthandcornerofthescreenwithSelectcolor
initsTitleBarandbluepreselected
Answer: B,FileChoosersandColorChoosers

19.

Amenusystemmayconsistofeachofthefollowing,except
(a) Checkboxmenuitem
(b) Comboboxmenuitem
(c) Radiobuttonmenuitem
(d) Menuitem
Answer: B,Menus

20.

Whichofthefollowingisnotaclassusedinconstructingamenusystem?
(a) JMenuItem
(b) JCheckBoxMenuItem
(c) JButton
(d) JRadioButtonMenuItem
Answer: C,Menus

21.

True/FalseInthefollowingcodethesetPreferredSizemethodsetsthesizeofthetext,Havea
goodday.
labelnewJlabel(Haveagoodday,SwingConstants.CENTER);
label.setPreferredSize(newDimension(400,200));
Answer: False,Menus

Chapter13AdvancedGUIApplications5

22.

TheDimensionclassispartofthe
(a) javax.swing.event.*package
(b) java.awt.*package
(c) javax.swing.*package
(d) java.awtpackage
Answer: D,Menus

23.

ArrangethefollowingsetsofcodeinthecorrectordertocreateaJMenuobjectconsistingofone
JMenuItemobject.
1

viewMenunewJMenu(View);
viewMenu.setMnemonic(KeyEvent.VK_V);
normalItemnewJMenuItem(Normal);
normalItem.setMnemonic(KeyEvent,VK_N);
normalItem.addActionListener(newNormalListener());
viewMenu.add(normalItem);

(a)
(b)
(c)
(d)

3,2,1
2,1,3
1,3,2
2,3,1

Answer: B,Menus
24.

Whatwillthefollowingcodedowhenitisexecuted?
JTextAreamessageJTextArea(greetings,50,70);
JScrollPanescrollPanenewJScrollPane(message);
(a) ItwillcreateaJScrollPaneobjectfortheJTextAreaobjectmessageanddisplayahorizontal
scrollbaronthetextarea
(b) ItwillcreateaJScrollPaneobjectfortheJTextAreaobjectmessageanddisplayaverticalscroll
baronthetextarea
(c) ItwillcreateaJScrollPaneobjectfortheJTextAreaobjectmessageanddisplaybothvertical
andhorizontalscrollbarsonthetextarea
(d) ItwillcreateaJScrollPaneobjectfortheJTextAreaobjectmessageanddisplaynoscrollbars
onthetextarea
Answer: C,MoreAboutTextComponents

25.

True/FalseWhenusingaslider,bydefault,tickmarksarenotdisplayed,andsettingtheirspacing
doesnotcausethemtobedisplayed.
Answer: True,Sliders

You might also like