JHTP自测题_第十二章_GUI组件(上篇)

来源:互联网 发布:java 开源项目源码 编辑:程序博客网 时间:2024/06/09 21:03


12.1Fill in the blanks in each of the following statements:

a) MethodMouseMoved is called when the mouse is moved with no buttons pressed and an event listener is registered to handle the event.

b) Text that cannot be modified by the user is calleduneditable (read-only) text.

c) A(n)layout manager arranges GUI components in aContainer.

d) Theaddmethod for attaching GUI components is a method of classContainer.

e) GUI is an acronym forGraphical User Interface.

f) MethodsetLayoutis used to specify the layout manager for a container.

g) AmouseDraggedmethod call is preceded by a(n)mousePressed method call and followed by a(n)mouseReleased method call.

h) ClassJOptionPane contains methods that display message dialogs and input dialogs.

i) An input dialog capable of receiving input from the user is displayed with methodshowInputDialog of classJOptionPane.

j) A dialog capable of displaying a message to the user is displayed with method showMessageDialog of classJOptionPane .

k) BothJTextFields andJTextAreas directly extend class JTextComponent.

12.2Determine whether each statement istrueorfalse. If false, explain why.

a)BorderLayoutis the default layout manager for aJFrame’s content pane. (True)

b) When the mouse cursor is moved into the bounds of a GUI component, methodmouseOveris called. (False, mouseEntered)

c) AJPanelcannot be added to anotherJPanel (False).

d) In aBorderLayout, two buttons added to the NORTHregion will be placed side by side. (False)

e) A maximum of five components can be added to aBorderLayout. (True)

f) Inner classes are not allowed to access the members of the enclosing class. (False)

g) AJTextArea’s text is always read-only (False).

h) ClassJTextAreais a direct subclass of classComponent (False).

12.3Find the error(s) in each of the following statements, and explain how to correct it (them):

a)buttonName = JButton("Caption");  ->new

b)JLabel aLabel, JLabel; (JLabel is a class name and cannot be used as a variable name)

c)txtField =newJTextField(50,"DefaultText"); (The arguments passed to the constructor are reversed. The String must be passed first.)

d)setLayout(newBorderLayout());

button1 =newJButton("North Star");

button2 =newJButton("South Pole");

add(button1);

add(button2);

0 0