Chapter 2
Swings
Each Question carries 1 Marks
Q1. An class listener interface and Event class Listener interface has same name.
A) adapter B) Static C) Inner D) Super
Q2. Filling the blank.
this.addComponentListener(new { public voidcomponentShown(ComponentEvent evt)
{
System.out.println("componentShown");
}
});
A) Component() B) componentadapter()
C) ComponentAdapter() D) ContainerAdapter()
Q3. Adapter Class and interfaces are same.
A) Sometimes B) Never C) True D) False
Q4. Adapter class saves __________.
A) Time B) Code C) Space D) All of the above
Q5. is a superclass of all AWT events that are handled by the delegation event model.
A) AWTEvent B) Event C) UtilityEvent D) AWT
Q6. Generates when the user enters a character.
A) Text Event B) Character Event
C) Label Event D) TextField Event
Q7. The method returns the object that generated the event.
A) Adjustable( ) B) getModifiers( )
C) getAdjustable( ) D) getAdjust( )
Q8. A class that have no name is known as inner class in java.
A) Anonymous B) Local C) Nested D) Static
Q9. Which are two ways to create Java Anonymous inner class ?
A) Class,Interface B) Class,Object
C) Interface,Object D) Class,Constructor
Q10. Which event is generates, when button is pressed?
A) TextEvent B) ItemEvent C) InputEvent D) ActionEvent
Q11. The AdjustmentEvent class defines integer constants.
A) ALT, CTRL, META, and/or SHIFT
B) BLOCK_DECREMENT, BLOCK_INCREMENT,TRACK
C) ALT,CTRL, UNIT_INCREMENT,UNIT_DECREMENT
D) UNIT_INCREMENT,UNIT_DECREMENT,SHIFT
Q12. ItemEvent class defines the integer constants.
A) DESELECT,SELECT B) DESELECTED,SELECTED
C) ENABLED,NOTENABLED D) CHECKED,UNCHECKED
Q13. The method returns a value that indicates which modifier keys were pressed when
the event was generated.
A) getModifiers( ) B) getAdjustable( )
C) Modifiers( ) D) Adjustable( )
Q14. Whose object is to be created to show any number of choices in the visible window?
A) JLabel B) JButton C) JList D) JCheckbox
Q15. Suppose you are developing a Java Swing application and want to toggle between
various viewsof the design area. Which of the views given below are present for the users to
toggle?
A) Design View B) Requirement View
C) Source View D) Toggle View
Q16. Which method will cause a JFrame to get displayed?
A) show( ) B) setVisible( )
C) showFrame( ) D) displayFrame( )
Q17. How to create the Tabbed pane in swings?
A) JTab jt=new JTab(); B) JTabPane jt=new JTabPane();
C) JTabP =new JTabP(); D) JTabbedPanejt=new JTabbedPane ();
Q18. What does the following line of code do? JTextfield text = new JTextfield(10);
A) Creates text object that can hold 10 columns of text.
B) Creates text object that can hold 10 rows of text.
C) Creates the object text and initializes it with 10.
D) The code is illegal
Q19. The Swing component classes that are used to encapsulate a mutually exclusive set of
buttons ?
A) AbstractButton B) ButtonGroup
C) JButton D) Button
Q20. Which Swing Component classes that are used to Encapsulates a mutually exclusive set
ofbuttons?
A) AbstractButton B) ButtonGroup C) JButton D) Button
Q21. Which method is used to add tooltip text to almost all components of Java swing?
A) getToolTipText() B) setToolTipText(String s)
C) setToolTip (String s) D) getToolTipText(String s)
Q22. In Swing the content pane can be obtained by using method.
A) getContent() B) getContentPane()
C) Both A & B D) getContainedPane()
Q23. Double-buffering built in, tool tips, dockable tool bars, keyboard , accelerators, custom
cursors,etc. are new features of ?
A) AWT B) Networking C) Swing D) All of the above
Q24. JCheckBox is Component .
A) heavyweight B) mediumweight C) No weight D) lightweight
Q25. Which of the following is not a constructor of JTree Class
A) JTree(Object obj[]) B) JTree(int x)
C) JTree(TreeNode tn) D) JTree()
Q26. Which of the following is not an AWT class?
A) Label B) CheckboxGroup C) RadioButton D) List
Q27. Which method of Choice class is used to return index of the selected item ?
A) getSelectedIndex() B) getSelectedIndexes()
C) getSelectedItem() D) getSelectedItems()
Q28. Swing components that don't rely on Native GUI are reffered to as
A) GUI component B) heavy weight component
C) Ligthweight component D) middle weight component
Q29. Developing GUI is swings does
A) uses buttons, menus, icons and all other components
B) should be easy for the end user to manipulate
C) stands for Graphic Use Interaction D) Both (a) and (c)
Q30. Which component cannot be added to a container?
A) JPanel B) JButton C) JFrame D) None of the above
Q31. A Swing component can be viewed based on what state it's in, how it looks, and what it
does.This is known as the model-view- model
A) Model B) Controller C) View D) None of the above
Q32. For using Swing control one must import package.
A) import javax.swing.* B) import java.swing.*
C) Both A & B D) None of the above
Q33. In Swing Buttons are the subclasses of which class?
A) AbstractButton B) Button
C) Both A & B D) None of the above
Q34. In Swing is a component that displays rows and columns of data.
A) Tabpane B) Table C) Scrollpane D) None of the above
Q35. What is the purpose of JTable?
A) JTable object displays ONLY rows
B) JTable object displays ONLY columns
C) JTable object displaysboth rows and columns
D) JTable object displays data in Tree form
Q36. Which of the following is TRUE?
A) Action method can be static method in a controller class
B) Action method can be private method in acontroller class
C) Action method can be protected method in a controller class
D) Action method must be public method in a controller class
Q37. A JTabbedPane does the following operations
A) arranges GUI components into layers such that only one layer is visible at a time
B) allows users to access a layer of GUI components via a tab
C) extends JComponent D) All of the above.
Q38. Where are the tabs on a JTabbedPane placed by default
A) top B) bottom C) left D) right.
Q39. Which of the following methods cannot be called on JLabel?
A) setIcon() B) getText() C) setLabel() D) setBorderLayout()
Q40. Menus are attached to the windows by calling method
A) addMenus() B) setMenu() C) setJMenuBar() D) addJMenuBar()
Q41. JRadioButton is a subclass of class.
A) AbstractButton B) ButtonGroup C) JButton D) ImageIcon
Q42. Which of the following is not a swing class?
A) JComboBox B) JFrame C) JComponent D) canvas
Q43. is a Swing class that allows the user to enter a multipleline of text
A) JLabel B) JTextField C) JTextArea D) JComboBox
Q44. is not a Swing Component
A) CheckboxGroup B) CheckBox C) JComboBox D) all the above
Q45. The Jtable of swings is used to display data in form of
A) JTable object displays rows and columns of data.
B) JTable object displays rows ONLY.
C) JTable object displays columns ONLY
D) none of the above
Q46. From Following list which is not a swing class?
A) ImageIcon B) JIcon C) JButton D) JPane
Q47. A array of strings is created for specifying the column headings in JTable.
A) two-dimensional B) one-dimensional
C) multi dimensional D) none of these
Q48. JProgressBar() of swings creates
A) Vertical Progress Bar Only B) Horizontal Progress Bar with Progress String.
C) Horizontal and Vertical Progress Bar without progress string.
D) Horizontal Progress Bar without progress string.
Q49. Which is correct statement from given option for using a table in an applet:
A) Create aJScrollPaneobject B) Add the table to the scroll pane.
C) Create aJTableobject D) All of theabove
Q50. Java Swings is used to create applications.
A) mobile enabled B) web based C) window based D) package based
Q51. To add tab to the panel which method is used?
A) addTab() B) addJPanel() C) addPanel() D) addJTab()
Q52. JComboBox control initially displays entry
A) One B) Two C) Empty D) NULL
Q53. JChoice control of swings is a kind of
A) Menu B) Item C) Radio D) List
Q54. Fill the blank at line no 5.
1. public class WindowExample extends Frame implements WindowListener
2. {
3. WindowExample()
4. {
5. (this);
6. setSize(400,400);
7.
setLayout(null);
8. setVisible(true);
9. }
A) addWindowListener B) addwindow
C) WindowListener() D) addwindowlistener
Q55. The getActionCommand( ) method returns-
A) String B) Object C) int D) void
Q56. The getItem( ) method returns-
A) String B) Object C) void D) int
Q57. Which method used to capture ALT, CTRL, META OR SHIFT keys-
A) getWhen( ) B) getActionCommand( )
C) getModifiers( ) D) getAdjustable( )
Q58. Select the interface: Which defines a method itemStateChanged()?
A) ItemState B) ContainerListener
C) ActionListener D) ItemListener
Q59. method is used to add the menubar to the frame.
A) setMenu() B) setMenuBar()
C) addMenuBar() D) All of the above
Q60. Select correct statement to add component in south region-----
A) add(component obj,FlowLayout.SOUTH);
B) add(component obj,BorderLayout.RIGHT);
C) add(component obj,BorderLayout.SOUTH);
D) add(component obj,FlowLayout.RIGHT);
Q61. What is use of GridLayout Manager ?
A) To lay out components in a two-dimensional grid
B) To lay components in tabular form
C) Both a and b
D) none of the above
Q62. is used when user wants to enter text that is not displayed,such as password.
A) setEditable() B) setEchoChar() C) getSelectedText() D) setText()
Q63. Which of the following is correct statement? Consider t1 as TextField object.
A) t1.setEchoChar('*'); B) t1.setEchoChar("*");
C) t1.setEchoChar('**'); D) None of these
Q64. Which of the following classes in Java contains swing version of an applet?
A) JButton B) JApplet C) AbstractButton D) JLabel
Q65. Which of the following value is not available to align arguments to use in Swing
Constantsinterface?
A) Left B) Right C) Middle D) Leading
Q66. In Java swing, which of the following components is/are represented by a rectangular
area inwhich a component may be viewed?
A) Scroll pane B) Tabbed pane C) Combo boxes D) None of these
Q67. Swing components are ultimately derived form which of the following ?
A) javax.awt.* B) java.awt.*
C) javax.swing.JComponent D) java.swing.*
Q68. Swing components are preceded by the letter
A) S B) A C) X D) J
Q69. The following are advanced components that comes with Swing except
A) Trees B) Lists C) Graph D) Table
Q70. In Java Swing, the JTable has a model called
A) JModel B) TableModel C) JRule D) JSwing
Q71. By default page-up and page-down increment of scrollbar is .
A) 20 B) 10 C) 15 D) 5
Q72. JComboBox constructors are
A) JComboBox( ) B) JComboBox(Vector v)
C) JComboBox(Vector v,Vector v) D) both a & b
Q73. Which Swing classes can be used with progress bars?
A) JProgressBar B) ProgressMonitor
C) ProgressMonitorInputStream D) all the above
Q74. Suppose a JFrame uses the GridLayout(2,0). If six buttons are added to the frame, how
manycolumns are displayed?
A) 1 B) 2 C) 3 D) 4
Q75. How many frames are c related ?
import java.awt.*;
import javax.swing.*;
public class FrameTest
{
public static void main(String args[])
JFrame fr=new JFrame("My frame");
JFrame fr1=fr;
JFrame fr2=fr1;
fr.setVisible(true);
fr1.setVisible(true);
fr2.setVisible(true);
}
A) 1 B) 2 C) 3 D) 0
Q76. The getStateChange ( ) method returns the state change.
A) The mouse pressed or released B) Selected or Deselected
C) A page-up or page-down D) Thewindow gained input focus.
Q77. Find the missing statement from the following code:
import javax.swing.*;
import java.lang.*;
public class ToolTipExample
{
public static void main(String[] args)
{
//Creating PasswordField and label
JPasswordField value = newJPasswordField();
value.setBounds(100,100,100,30);
value.setToolTipText("Enter your Password");
JLabell1=new JLabel("Password:");
l1.setBounds(20,100, 80,30); //Adding components to frame
f.add(value);
f.add(l1);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
A) JPanel p=new JPanel("Password Field Example");
B) JFrame f=new JFrame("Password Field Example");
C) JContentPane c=new JContentPane("Password Field Example");
D) none of the above
Q78. Swing is a ----------------------------- , whose components are all ultimately derived from
the javax.swing.JComponent class.
A) Model-Based B) component-based framework
C) Relational Based D) None of the above
Q79. Constructor of JCheckBoxMenuItem is
A) JCheckBoxMenuItem() B) JCheckBoxMenuItem(Action a)
C) JCheckBoxMenuItem(String text, boolean b) D) All of the above
Q80. Constructor of JTable is
A) JTable() B) JTable(Object[][] rows, Object[] columns)
C) Both A & B D) None of the above
Q81. What is the difference between scrollbar and scrollpane
A) A Scrollpane is a Component, but not a Container whereas Scrollbar is a
Container and handles its ownevents and perform its own scrolling.
B) A Scrollbar is a Component, but not a Container whereas Scrollpane is a
Container and handles its own events and perform its own scrolling
C) A Scrollbar is handles not its own events and perform its own scrolling.
whereas Scrollpane handles not its own events and perform its own scrolling
D) all the above
Q82. What does x mean in javax.swing
A) x mean in javax.swing is Extension of java
B) x mean in javax.swing is Extreme of java
C) x mean injavax.swing is Ex. of java
D) x mean in javax.swing is Extra of java
Q83. Find missing statement to get the output shown
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class LabelExample extends Frame implements ActionListener
{
JTextField tf;
JLabel l;
JButton b;
LabelExample()
{
tf=new JTextField();
tf.setBounds(50,50, 150,20); l=new JLabel();
l.setBounds(50,100, 250,20);
b=new JButton("Find IP");
b.setBounds(50,150,95,30);
b.addActionListener(this);
add(b);
add(tf);
add(l);
setSize(400,400);
setLayout(null);
setVisible(true);
}
publicvoid actionPerformed(ActionEvent e)
{
Try
{
String host=tf.getText();
_____________ l.setText("IP of "+host+" is: "+ip);
}
catch(Exceptionex)
{
System.out.println(ex);
}
}
public static void main(String[] args)
{
new LabelExample();
}
}
A) String ip=java.net.InetAddress.getHostAddress();
B) String ip=java.net.InetAddress.getByName(host).getHostAddress();
C) String ip=java.net.InetAddress.getByName(host);
D) None of the above
Q84. TreeNode and MutableTreeNode is
A) Both are classes B) class and interface
C) Both are interfaces D) interface and class
Q85. Which of the following GridBagLayout variable defines the external padding
(border) around thecomponent in its display area?
A) gridwidth, gridheight B) gridx, gridy C) ipadx, ipady D) insets
Q86. Which of the following GridBagLayout variables defines the padding that gets
added to each sideof the component?
A) gridwidth, gridheight B) gridx, gridy
C) ipadx, ipady D) insets
Q87. Which component displays information in hierarchical manner with parent-child
relationship?
A) AWT B) Frame C) Swing D) Window
Q88. Swing is the set of __________ that provides more powerful & flexible
components ascompare to Abstract Window Tooklit (AWT).
A) constructors B) methods C) classes D) destructors
Q89. The class JList is a component which displays and
allows the user to select one ormore items.
A) List of lists B) list of objects C) MVC Model D) Item List
Q90. AbstractButton is the template class for
A) Push Buttons B) Radio Buttons
C) Check boxes D) All of the above.
Q91. What is use of 5th parameter in given constructor Scrollbar(int,int,int,int,int)
A) orientation B) visible C) maximum D) minimum
Q92. Which of the following is the Java toolkit used to write GUI programs?
A) GUI toolkit B) Abstract Windowing Toolkit
C) Graphics Event Toolkit D) Java Enhancement Toolkit
Q93. Which of the following determines how the components of a container are
displayed?
A) Display Manager B) Component Manager
C) Stage Manager D) Layout Manager
Q94. When a Dialog box is active, it blocks user input to all other windows in the program
A) modal B) modeless C) file D) none of the above
Q95. Text Fields is also know as
A) Single line control B) Active Control
C) Passive Control D) Edit Control
Q96. Which of the following method is used to show the specific card?
A) public void show(Container parent, String name)
B) public void show(Container parent)
C) public voidfirst(Container parent, String name)
D) public void next(Container parent, String name)
Q97. The constructors in BorderLayout class are------------
A) BorderLayout() B) BorderLayout(int hgap, int vgap)
C) Both a and b D) None of the above
Q98. The constructors in GridLayout class are-----------
A) GridLayout() B) GridLayout(int rows, int cols)
C) GridLayout(int rows, int cols, int hgap, int vgap) D)All of the above
Q99. Which method is used to find out the number of rows in the grid layout?
A) int getRows() B) void getRows()
C) void getRows(int) D) None of the above
Q100. Which method is used to know the mode of the FileDialog.?
A) int getMode() B) void getMode()
C) int getMode(int) D) void getMode(int)