Previous | Home | Next |
Answer: Controls are componenets that allow a user to interact with your application.
The AWT supports the following types of controls:
- Labels
- Push buttons
- Check boxes
- Choice lists
- Lists
- Scroll bars
- Text components
These controls are subclasses of Component.
Q.2 You want to construct a text area that is 80 character-widths wide and 10 character-heights tall. What code do you use?
(a). new TextArea(80, 10)
(b). new TextArea(10, 80)
Answer: (b). new TextArea(10, 80)
Q.3 A text field has a variable-width font. It is constructed by calling new TextField("iiiii"). What happens if you change the contents of the text field to "wwwww"? (Bear in mind that is one of the narrowest characters, and w is one of the widest.)
(a). The text field becomes wider.
(b). The text field becomes narrower.
(c). The text field stays the same width; to see the entire contents you will have to scroll by using the and keys.
(d). The text field stays the same width; to see the entire contents you will have to scroll by using the text fields horizontal scroll bar.
Answer: (c). The text field stays the same width; to see the entire contents you will have to scroll by using the and keys.
(a). True
(b). False
Answer: (b). False
(a). Container - class
(b). MenuComponent - class
(c). Dialog - class
(d). Applet - class
(e). Menu - class
Answer:
(a). Container - class
(b). MenuComponent - Object
(c). Dialog - Window
(d). Applet - Panel
(e). Menu - MenuItem
Answer: TextField and TextArea
Q.7 Which method of the component class is used to set the position and the size of a component?
Answer: setBounds()
Q.8 Which TextComponent method is used to set a TextComponent to the read-only state?
Answer: setEditable()
Answer: By associating Checkbox objects with a CheckboxGroup.
Q.10 What Checkbox method allows you to tell if a Checkbox is checked?
Answer: getState()
(a). getVisible()
(b). getImmediate
(c). getParent()
(d). getContainer
Answer: (c). getParent()
Answer: getLabel( ) and setLabel( )
Answer:
A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice.
A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.
Answer: validate( )
Answer: A Scrollbar is a Component, but not a Container. A Scrollpane is a Container and handles its own events and performs its own scrolling.
Answer: Canvas.
(a). Button
(b). Label
(c). CheckboxMenuItem
(d). Toolbar
(e). Frame
Answer:
(a). Button
(b). Label
(e). Frame
(a). Frame
(b). TextArea
(c). MenuBar
(d). FileDialog
(e). Applet
Answer
(a). Frame
(d). FileDialog
(e). Applet
(a). setText( )
(b). setLabel( )
(c). setTextLabel( )
(d). setLabelText( )
Answer: (a). setText( )
(a). new TextArea(10, 20))
(b). new TextArea(20, 10)
(c). new TextArea(new Rows(10), new columns(20))
(d). new TextArea(200)
Answer: (a). new TextArea(10, 20))
(a). new List(5, true)
(b). new List(true, 5)
(c). new List(5, false)
(d). new List(false,5)
Answer: (a). new List(5, true)
(a). The validate( ) method is used to cause a Container to be laid out and redisplayed.
(b). The add( ) method is used to add a Component to a Container.)
(c). The getBorder( ) method returns information about a Containers insets.
(d). The getComponent( ) method is used to access a Component that is contained in a Container.
Answer:
(a). The validate( ) method is used to cause a Container to be laid out and redisplayed.
(b). The add( ) method is used to add a Component to a Container.)
(d). The getComponent( ) method is used to access a Component that is contained in a Container.
Q.23 Suppose a Panel is added to a Frame and a Button is added to the Panel. If the Frames font is set to 12-point TimesRoman, the Panels font is set to 10-point TimesRoman, and the Buttons font is not set, what font will be used to dispaly the Buttons label?
(a). 12-point TimesRoman
(b). 11-point TimesRoman
(c). 10-point TimesRoman
(d). 9-point TimesRoman
Answer: (c). 10-point TimesRoman
Q.24 A Frames background color is set to Color.Yellow, and a Buttons background color is to Color.Blue. Suppose the Button is added to a Panel, which is added to the Frame. What background color will be used with the Panel?
(a). Colr.Yellow
(b). Color.Blue
(c). Color.Green
(d). Color.White
Answer: (a). Colr.Yellow
(a). show( )
(b). setVisible( )
(c). display( )
(d). displayFrame( )
Answer:
(a). show( )
(b). setVisible( )
Answer: Object.
Answer: add ( ) method.
Answer: The Container class has three major subclasses. They are :
- Window
- Panel
- ScrollPane
(a). True
(b). False
Answer: (b). False
(a). True
(b). False
Answer: (b). False
Answer: TextField and TextArea.
Answer: CheckboxGroup.
(a). Non-exclusive Checkboxes.
(b). Radio buttons.
(c). Choice.
(d). List.
Answer:
(a). Non-exclusive Checkboxes.
(d). List.
Answer: Java supports two types of Checkboxes. They are : Exclusive and Non-exclusive.
In case of exclusive Checkboxes, only one among a group of items can be selected at a time. I f an item from the group is selected, the checkbox currently checked is deselected and the new selection is highlighted. The exclusive Checkboxes are also called as Radio buttons.
The non-exclusive checkboxes are not grouped together and each one can be selected independent of the other.
Q.35 What is a Layout Manager and what are the different Layout Managers available in java.awt and what is the default Layout manager for the panal and the panal subclasses?
Answer: A layout Manager is an object that is used to organize components in a container.
The different layouts available in java.awt are :
- FlowLayout, BorderLayout, CardLayout, GridLayout and GridBag Layout.
- The default Layout Manager of Panal and Panal sub classes is FlowLayout.
Answer: Yes
- myPanal.setLayout(null);
- myPanal.setbounds(20,20,200,200);
Answer: No. Adding a component to a container automatically removes it from any previous parent(container).
Answer: Use setBounds, setSize, or setLocation methods to implement this.
- setBounds(int x, int y, int width, int height)
- setBounds(Rectangle r)
- setSize(int width, int height)
- setSize(Dimension d)
- setLocation(int x, int y)
- setLocation(Point p)
Answer: Create an instance of the Window class, give it a size, and show it on the screen.
Eg. Frame aFrame = ......
- Window aWindow = new Window(aFrame);
- aWindow.setLayout(new FlowLayout());
- aWindow.add(new Button("Press Me"));
- aWindow.getBounds(50,50,200,200);
- aWindow.show();
Answer: Yes. By using setResizable() method in class Frame.
Q.41 What is the default Layout Manager for the Window and Window subclasses (Frame,Dialog)?
Answer: BorderLayout().
Answer:
FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion.
BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container.
CardLayout: The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.
GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid.
GridBagLayout: The elements of a GridBagLayout are organized according to a grid.However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.
Answer: The Window, Frame and Dialog classes use a BorderLayout as their default layout.
Answer: The Panel and the Applet classes use the FlowLayout as their default layout.
Answer: The preferred size of a component size that will allow the component to display normally.
(a). startLayout( )
(b). initLayout( )
(c). layoutContainer( )
(d). setLayout( )
Answer: (d). setLayout( )
(a). getPreferredSize( )
(b). getPreferred( )
(c). getRequiredSize( )
(d). getLayout( )
Answer: (a). getPreferredSize( )
Q.48 Which layout should you use to organize the components of a container in a tabular form?
(a). CardLayout
(b). BorederLayout
(c). FlowLayout
(d). GridLayout
Answer: (d). GridLayout
Q.49 An application has a frame that uses a Border layout manager. Why is it probably not a good idea to put a vertical scroll bar at North in the frame?
(a). The scroll bars height would be its preferred height, which is not likely to be enough.
(b). The scroll bars width would be the entire width of the frame, which would be much wider than necessary.
(c). Both a and b.
(d). Neither a nor b. There is no problem with the layout as described.
Answer: (c). Both a and b.
Answer: For an applet and a panel, Flow layout is the default layout, whereas Border layout is default layout for a frame.
Q.51 If a frame uses a Grid layout manager and does not contain any panels, then all the components within the frame are the same width and height.
(a). True
(b). False
Answer: (a). True
Q.52 If a frame uses its default layout manager and does not contain any panels, then all the components within the frame are the same width and height.
(a). True
(b). False
Answer: (b). False
Q.53 With a Border layout manager, the component at Center gets all the space that is left over, after the components at North and South have been considered.
(a). True
(b). False
Answer: (b). False
Q.54 An Applet has its Layout Manager set to the default of FlowLayout. What code would be the correct to change to another Layout Manager?
(a). setLayoutManager(new GridLayout());
(b). setLayout(new GridLayout(2,2));
(c). setGridLayout(2,2,))
(d). setBorderLayout();
Answer: (b). setLayout(new GridLayout(2,2));
(a). North, South,East,West
(b). Assign a row/column grid reference
(c). Pass a X/Y percentage parameter to the add method
(d). Do nothing, the FlowLayout will position the component
Answer: (d). Do nothing, the FlowLayout will position the component
(a). Use the setLayout method
(b). Once created you cannot change the current layout manager of a component
(c). Use the setLayoutManager method
(d). Use the updateLayout method
Answer: (a). Use the setLayout method
Q.57 When using the GridBagLayout manager, each new component requires a new instance of the GridBagConstraints class. Is this statement true or false?
(a). True
(b). False
Answer: (b). False
(a). The default layout manager for an Applet is FlowLayout
(b). The default layout manager for an application is FlowLayout
(c). A layout manager must be assigned to an Applet before the setSize method is called
(d). The FlowLayout manager attempts to honor the preferred size of any components
Answer:
(a). The default layout manager for an Applet is FlowLayout
(d). The FlowLayout manager attempts to honor the preferred size of any components
Q.59 Which method does display the messages whenever there is an item selection or deselection of the CheckboxMenuItem menu?
Answer: itemStateChanged method.
Answer: CheckboxMenuItem.
Answer: setState(boolean).
(a). A separator
(b). A check box
(c). A menu
(d). A button
(e). A panel
Answer:
(a). A separator
(c). A menu
(a). A panel
(b). A frame
(c). An applet
(d). A menu bar
(e). A menu
Answer: (b). A frame
Answer: The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked.
(a). A Dialog can have a MenuBar.
(b). MenuItem extends Menu.
(c). A MenuItem can be added to a Menu.
(d). A Menu can be added to a Menu.
Answer:
(c). A MenuItem can be added to a Menu.
(d). A Menu can be added to a Menu.
Previous | Home | Next |