Java Test
Java Test
Daniel
Liang
A. All the methods in the JButton class are inherited from the javax.swing.AbstractButton class.
2 The method __________ gets the text (or caption) of the button jbt.
A. jbt.text()
B. jbt.getText()
C. jbt.findText()
D. jbt.retrieveText().
3 The method __________ creates a IconImage for file c:\image\us.gif.
A. new ImageIcon("c:\image\us.gif");
B. new Icon("c:\image\us.gif");
C. new ImageIcon("c:\\image\\us.gif");
D. new Icon("c:\\image\\us.gif");
A. jbt.setMnemonic("A");
B. jbt.setMnemonic('A');
C. jbt.setIconTextGap(50);
D. jbt.setTextGap(50);
5 The method __________ specifies that the text and icon are horizontally aligned to the right in the
button jbt.
A. jbt.setVerticalTextPosition(JButton.LEFT)
B. jbt.setHorizontalTextPosition(JButton.LEFT)
C. jbt.setHorizontalTextPosition(JButton.RIGHT)
D. jbt.setHorizontalAlignment(JButton.RIGHT)
E. jbt.setHorizontalAlignment(JButton.LEFT)
6 The method __________ specifies that the text is placed on the right of the icon in the button jbt.
A. jbt.setVerticalTextPosition(JButton.LEFT)
B. jbt.setHorizontalTextPosition(JButton.LEFT)
C. jbt.setHorizontalTextPosition(JButton.RIGHT)
D. jbt.setHorizontalAlignment(JButton.RIGHT)
E. jbt.setHorizontalAlignment(JButton.LEFT)
import javax.swing.*;
import java.awt.*;
getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(p2, BorderLayout.SOUTH);
getContentPane().add(p3, BorderLayout.CENTER);
}
C. Only jbt1 displays the icon and jbt2 does not display the icon.
import javax.swing.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
C. The program has a syntax error because you assign new TitledBorder("My button") to a variable
of the Border type.
D. The program has a runtime error because you cannot set a border on a button.
A. jchk.getSelected()
B. jchk.selected()
C. jchk.isSelected().
D. jchk.select()
B. ItemEvent
C. ComponentEvent
D. ContainerEvent
A. You can create an instance of ButtonGroup and add radio button to the instance to group the
buttons.
D. By default, when a radio button is created, the radio button is not selected.
B. ItemEvent
C. ComponentEvent
D. ContainerEvent
E. a and b
17 The method __________ gets the text (or caption) of the label jlbl.
A. jlbl.text()
B. jlbl.getText()
C. jlbl.findText()
D. jlbl.retrieveText().
18 Which of the following are valid methods on the label jlbl.
A. jlbl.setMnemonic("A");
B. jlbl.setMnemonic('A');
C. jlbl.setIconTextGap(50);
D. jlbl.setTextGap(50);
19 The method __________ specifies that the text and icon are horizontally aligned to the right in the
label jlbl.
A. jlbl.setVerticalTextPosition(JButton.LEFT)
B. jlbl.setHorizontalTextPosition(JButton.LEFT)
C. jlbl.setHorizontalTextPosition(JButton.RIGHT)
D. jlbl.setHorizontalAlignment(JButton.RIGHT)
E. jlbl.setHorizontalAlignment(JButton.LEFT)
20 The method __________ specifies that the text is placed on the right of the icon in the label jlbl.
A. jlbl.setVerticalTextPosition(JButton.LEFT)
B. jlbl.setHorizontalTextPosition(JButton.LEFT)
C. jlbl.setHorizontalTextPosition(JButton.RIGHT)
D. jlbl.setHorizontalAlignment(JButton.RIGHT)
E. jlbl.setHorizontalAlignment(JButton.LEFT)
21 The method __________ assigns the name Result to the Text of variable jlbl.
A. jlbl.setText("Result")
B. jlbl.newText("Result")
C. jlbl.text("Result")
D. jlbl.findText()
A. A label
B. A button
C. A check box
D. A radio button
E. A text field
23 Which of the following statements are true?
24 The method __________ gets the contents of the text field jtf.
A. jtf.getText(s)
B. jtf.getText()
C. jtf.getString()
D. jtf.findString()
25 The method __________ appends a string s into the text area jta.
A. jta.setText(s)
B. jta.appendText(s)
C. jta.append(s)
D. jta.insertText(s)
A. jta.setLineWrap(false)
B. jta.setLineWrap(true)
C. jta.WrapLine()
D. jta.wrapText()
A. jta.setWrapStyleWord(false)
B. jta.setWrapStyleWord(true)
C. jta.wrapStyleWord()
D. jta.wrapWord()
A. jScrollPane.add(jta)
B. jScrollPane.insert(jta)
C. jScrollPane.addItem(jta)
A. 0
B. 1
C. 2
D. Unlimited
B. 1
C. 2
D. Unlimited
A. jcbo.getSelectedIndex()
B. jcbo.getSelectedItem()
C. jcbo.getSelectedIndices()
D. jcbo.getSelectedItems()
A. jcbo.add(s)
B. jcbo.addChoice(s)
C. jcbo.addItem(s)
D. jcbo.addObject(s).
34 Clicking a JComboBox object always generates __________ events.
A. ActionEvent
B. ItemEvent
C. MouseEvent
D. KeyEvent
E. WindowEvent
A. if an item is selected.
36 ____________ is a component that enables the user to choose a single value or multiple values.
A. A text field
B. A combo box
C. A list
D. A label
37 ______________ allows selections of multiple contiguous items without restrictions,
A. Single selection
B. Single-interval selection
C. Multiple-interval selection
D. default selection
38 ______________ sets the background of the selected item in list jlst to yellow.
A. jlst.setBackground(Color.YELLOW)
B. jlst.setSelectedBackground(Color.YELLOW)
C. jlst.setSelectionBackground(Color.YELLOW)
D. jlst.setSelectionbackground(Color.YELLOW)
A. minimum
B. maximum
C. orientation
D. visibleAmount
A. minimum
B. maximum
C. orientation
D. visibleAmount