Advanced Java Ajp
Advanced Java Ajp
Unit :01
Abstract Windowing Toolkit (AWT)
1) The various controls supported by AWT are
a) Labels, push buttons
b) Checkboxes, choice, list
c) Scroll bars, text area, text field
d) All of these
2) The concept of the menu bar can be implemented by using three java classes—
a) MenuBar
b) Menu
c) MenuItem
d) All of these
b) Object
c) Int
d) String
5) The classes and interfaces defined in AWT are contained within the ______ package.
a) java.awt.*
b) java.sql.*
c) java.io.*
d) java.int*
7) The AWT container is an instance of the ___________ class which holds various
components and other containers
a) Graphics
b) Container
c) Eventobj
d) None of these
d) Both a & b
c) Both a & b
d) None of these
11) An event is generated when the internal state of the event source is________
a) Not changed
b) Changed
c) Either changed or not
d) None of these
12) Positions the components into five regions:east, west, north, south, center
a) BorderLayout
b) CardLayout
c) GridLayout
d) FlowLayout
13) Arranges the components as a deck of cards such that only one component is visible at a
time
a) BorderLayout
b) CardLayout
c) GridLayout
d) FlowLayout
d) FlowLayout
c)GridLayout
d) FlowLayout
17) The Component class is an abstract class and so its ____________ are used to create
components.
a) Subclasses
b)Superclasses
c) Both a & b
d)None of these
18) The AWT classes can be roughly categorized into the following groups:
a) GUI Components
b) Layouts
c) Graphics Tools
d) Event Handlers
e) All of these
d) None of these
c) Both a & b
d) None of these
24) Regular menus are placed at the __________ of the application window within a menu
bar
a) Top
b) Bottom
c) Top-down
d) Botttom-up
25) The text field and text area controls create a _________________ area respectively
a) Single-line text
b) Multi-line text
c) Both a & b
d) None of these
c) Three dimensional
d) None of these
27) _____________ is a superclass of TextField and TextArea classes that is used to create
single-line or multiline textfields respectively:
a)TextBox
b)CheckBox
c)TextComponent
d)Choice
a) Text(non-editable)
b) Text(editable)
c) Both a & b
d) None of these
29) ______________ is an abstract class that encapsulates all of the attributes of a visual
component.
a)Component
b)Window
c)Frame
d) Panel
30) A _______ object is responsible for remembering the current foreground and
background colors
a)Window
b)Component
c)None
d)Both
a) Container
b) Window
c) Frame
d) none
c) Panel
d ) None
c) Applet
d) None
34) Which is a container that does not contain a title bar, menu bar, or border?
a)Window
b)Frame
c)Panel
d)Container
35)Name the class used to represent GUI component that has a title bar, menu bar, borders,
and resizing corners.
a) Window
b) Container
c) Frame
d) Panel
b) 2
c) 3
d) 4
37) Which method is used to set title for the Frame window?
a)Frame()
b)Frame(String title)
c) Frame(String title,int x,int y)
d) None
39) The ____ method is used to obtain the current size of a window.
a) getSize()
b)setSize()
c)None
d)Both
40)Which method is used for hiding and showing a window in the frame window.
a)setVisible()
b)getVisible( )
c)both
d)None
c) WindowListener
c) None
42) Which of these packages contains all the classes and methods required for event
handling
a) java.awt.Applet;
b) java.awt.event;
c) java.awt;
d) java.event;
43) On invoking repaint() method for a Component the method invoked by AWT is:
a)draw( )
b)show( )
c)update( )
d) paint( )
d)WindowListener
c)Canvas
d)None
a)Component
b)Frame
c)Window
d)Panel
b)AWTEventMulticaster
c)AWTEventManager
d) All of the Above
48) Add instance of the desired control to the window by calling ____ method, defined by
____ class.
a)add() , Container
b)add() , Component
c)addTo() , Container
d)addTo(), Component
a)removeControl()
b)remove()
c)removeAll()
d)None of the above
d)removeAll( )
52)In the Label(String str, int how) constructor value of how will be-
53)To set or change the text in a label __ method and to obtain the current label by calling
___ method is used.
a)setTxt() , getTxt()
b)settext() , gettext()
c)setText() , getText()
d)getText() , setText()
54)To set the alignment of the string within the label by calling ___ method ,to obtain the
current alignment ___ method is used.
a)getAlignment( ) ,setAlignment( )
b)setAlign( ) ,getAlign( )
c)setAlignment( ) ,getAlignment( )
d)getAlign( ) ,setAlign( )
57) Set label of a button by calling __ method and can retrieve its label by calling __
method.
a) getLabel( ) , setLabel( )
b) setLabel( ) , getLabel( )
c) getlabel( ) , setlabel( )
d) d)setlabel( ) , getlabel( )
d) action event
a)ActionListener
b)ItemListener
c)MouseListener
d)FocusListener
a)ActionListener
b)ItemListener
c)MouseListener
d)FocusListener
61)Which class can be used to represent a checkbox with a textual label that can appear in a
menu.
a)MenuBar
b) MenuItem
c)CheckboxMenuItem
d)Menu
62) To retrieve the current state of a check box, call __ method , to set its state, call __
method.
a) setState( ) , getState( )
b) getState( ) , setState( )
c) setstate( ) , getstate( )
d) getstate( ) , setstate( )
a)ItemListener , ItemEvent
b)MouseListener , MouseEvent
c)ActionListener , ActionEvent
d)KeyListener , KeyEvent
a)actionPerformed()
b)ActionPerformed()
c)itemStateChanged()
d)ItemstateChanged()
66) .It is possible to create a set of mutually exclusive check boxes in which one and only
one check box in the group can be checked at any one time by using __ component.
a) CheckboxGroup
b) Radio Button
c) Checkbox
d) Choice
67) You can determine which checkbox in a group is currently selected by calling __
method.
a)getselectedCheckbox( )
b)GetSelectedCheckbox( )
c)getSelectedCheckbox( )
d)None of the above
c)getselectedCheckbox( )
d)getSelectedCheckbox( )
69)In which of the following the only one checkbox will be selected.
a)Checkbox Win98 = new Checkbox("Windows 98/XP", cbg, false);
70) Which class is used to create a pop-up list of items from which the user may choose.
a) Choice
b) List
c) Checkbox
d) CheckboxGroup
72)To determine which item is currently selected, you may call either ___ or ____ method.
a)setSelectedItem( ),setSelectedIndex( )
b)GetSelectedItem( ),GetSelectedIndex( )
c)getSelectedItem( ),getSelectedIndex( )
d)getselectedItem( ),getselectedIndex( )
75) Scrollbar uses which two constants to create horizontal and vertical scrollbar.
a)Scrollbar.Vertical , Scrollbar.Horizontal
b)Vertical.SCROLLBAR , Horizontal.SCROLLBAR
c)Scrollbar.VERTICAL , Scrollbar.HORIZONTAL
d)None of the above
76) To obtain the current value of the scroll bar, call ___, to set the current value, call __
method.
a) setvalue( ), getvalue( )
b) setValue( ) , getValue( )
c) getvalue( ). setvalue( )
d) getValue( ) , setValue( )
77) You can retrieve the minimum and maximum values of scrollbar by __ and___ method
a)getMinimum( ), getMaximum( )
b)getMax(), getMin()
c)setMinimum(), setMaximum()
d)setMax(), setMin()
b)AdjustmentListener
c)MouseMotionListener
d)ItemListener
b)TextField class
c)both a & b
d)none of the above
c)TextField(int rows)
d)TextField(Stringstr)
81) To obtain the text currently in the text field, which method is used?
a) getWord()
b) getString()
c) getText()
d) getRow()
82) Program can obtain the currently selected text by calling _________
a) getSelectedText()
b) getText()
c) getSelected()
d) getEdit()
a) setEditable( )
b) getEditable()
c) isEditable()
d) None of the above
b) setEchoChar( )
c) hideText()
d) setChar()
b)TextArea
c)Editor
d)Label
a)TextArea(String str)
b)TextArea(intnumLines, intnumChars)
c)TextArea(Stringstr, intnumLines, intnumChars, intsBars)
d)TextArea(Stringstr, intsrows)
b) setFormat()
c) setText()
d) SetEditable()
88) The________method appends the string specified by str to the end of the current text.
a)append()
b)insertText()
c)attach()
d)editText()
89) ____ method inserts the string passed in str at the specified index.
a)append()
b)attachText()
c)insert()
d)join()
d) replaceRange()
91) Each ______ object has a layout manager associated with it.
a) Applet
b) Frame
c) Panel
d) Container
92) A layout manager is an instance of any class that implements the _______ interface.
a) LayoutManager
b) ActionListener
c) ItemListener
d) MouseListener
c) setLayout( )
d) setVisible()
94) Which method is used to determine position and shape of a component manually
a) setBounds()
b) setPosition()
c) Both a and b
d) None
95) Which of the following LayouManager is/are consulted whenever the container needs to
be resized
a) minimumLayoutSize( )
b) preferredLayoutSize( )
c) Both
d) None
a) getPrefferedSize(),getMinimumSize( )
b) getPrefferedsize(),getMinimumsize( )
c) getprefferedSize(),getminimumSize( )
d) None
a) FlowLayout()
b) BorderLayout()
c) GridLayout()
d) CardLayout()
99) In the constructor FlowLayout(int how, int horz, int vert) what is the value of how
a) FlowLayout.LEFT,FlowLayout.CENTER,FlowLayout.RIGHT
b) FlowLayout.TOP,FlowLayout.BOTTOM,FlowLayout.CENTE
c) FlowLayout.EAST,FlowLayout.WEST, FlowLayout.CENTER
d) None
d) Both a and b
a) BorderLayout.CENTER,BorderLayout.SOUTH,BorderLayout.EAST,
BorderLayout.WEST, BorderLayout.NORTH
b) BorderLayout.CENTER, BorderLayout.TOP, BorderLayout.BOTTOM,
BorderLayout.LEFT, BorderLayout.RIGHT
c) BorderLayout.CENTER, BorderLayout.LEFT, BorderLayout.RIGHT,
d) None of the above
d) Two-dimensional
104) The CardLayout class is ______ among the other layout managers in that it stores
several different _____.
a) unique,classes
b) unique,layout
c) antique,methods
d) special,packages
c) Panel
d) Container
b)only first 2
c)Both
d)None
d) modal,modeless
c) Object
d) Package
c) FileDialog.LOAD
d) FileDialog.READ
a) FileDialog.SAVE
b) FileDialog.WRITE
c) FileDialog.LOAD
d) FileDialog.READ
116) Select the correct Menubar classes from the following options
117) Which menu option of types will have a checkmark next to them when they are
selected?
a) CheckboxMenuItem
b) CheckedItem
c) MenuItem
d) None of these
118) You can disable or enable a menu item by using the ____________method.
a) setStatus()
b)setEnabled( )
c) setMenuStatus()
d)None of these
d) All of these
120) Which sets the command name of the action event that is fired by this menu item?
a) setActionCommand()
b) setMenuCommand()
c) Both
d) None of these
a) true, setState()
b) check, setItemStatus()
c) check, setItemState()
d) None of these
123)
import java.awt.*;
import java.applet.*;
import java.util.*;
/*
<applet code="BorderLayoutDemo" width=400 height=200>
</applet>
*/
public class BorderLayoutDemo extends Applet
{
public void init() {
add(new Button("north."),BorderLayout.NORTH);
add(new Button("south"),BorderLayout.SOUTH);
add(new Button("Right"), BorderLayout.EAST);
add(new Button("Left"), BorderLayout.WEST);
String msg = "this is in center";
add(new TextArea(msg), BorderLayout.CENTER);
}
}
a) SetLayout(new BorderLayout());
b) setLayout(new BorderLayout());
c) setLayout(new Borderlayout());
d) setLayout(new borderLayout());
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="CBGroup" width=250 height=200>
</applet>
*/
public class CBGroup extends Applet
{
String msg = "";
Checkbox Win98, winNT;
CheckboxGroup cbg;
public void init()
{
cbg = new CheckboxGroup();
Win98 = new Checkbox("Windows 98/XP", , true);
winNT = new Checkbox("Windows NT/2000", , false);
add(Win98);
add(winNT);
Win98.addItemListener(this);
winNT.addItemListener(this);
}
}
a) Win98
b) winNT
c)cbg
d)this
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
add(os);
}
a)Listener missing
b)applet code is missing
c)package missing
d)All
a)
b)
c)
d)
Answer: a)
}
}
a) Firstlabel object is not declared
b) Secondlabel object is not declared
c) b1 object is not declared
d) All of above
128) What will be the missing statement in java to get following output:
import java.awt.*;
import java.applet.*;
/*<applet code=fontc width=500 height=500>
</applet>
*/
public class fontc extends Applet
{
public void init()
{
Font f=new Font("Times New Roman",Font.ITALIC,30)
setFont(f);
}
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawString("SAGAR",10,50);
}
}
A. Missing {
B. Missing }
C. Missing semicolon
D. Missing ()
a) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");
b1=new Button("Enter");
add(l1);
add(l2);
add(b1);
}
}
b) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
b1=new Button("Enter");
add(l1);
add(b1);
}
}
c) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");
add(l1);
add(l2);
}
}
d) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");
b1=new Button("Enter");
add(l1);
add(l2);
add(b1);
}
}
import java.awt.*;
import java.applet.*;
/*
<applet code="GridLayoutDemo" width=300 height=200></applet>
*/
public class GridLayoutDemo extends Applet
{
int n = 4;
public void init()
{
setLayout(new GridLayout(n,n,10,10));
b)
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class MenuFrame1 extends Frame
{
String msg = "";
MenuBar mbar;
MenuItem copy,paste,selectline,selectword,selectall;
CheckboxMenuItem open,cut;
TextField t1;
Menu file,edit,select,format;
public MenuFrame1()
{
mbar =new MenuBar();
setMenuBar(mbar);
file = new Menu("File");
open = new CheckboxMenuItem("open");
file.add(open);
mbar.add(file);
edit= new Menu("edit");
cut = new CheckboxMenuItem("cut");
copy = new MenuItem("copy");
paste = new MenuItem("paste");
edit.add(cut);
edit.add(copy);
edit.add(paste);
select =new Menu("select");
selectline = new MenuItem("selectline");
selectword = new MenuItem("selectword");
selectall = new MenuItem("selectall");
selectall.setEnabled(false);
select.add(selectline);
select.add(selectword);
select.add(selectall);
edit.add(select);
mbar.add(edit);
format =new Menu("format");
format.setEnabled(false);
mbar.add(format);
addWindowListener(new MyWindowAdapter1());
}
public static void main(String[] args)
{
MenuFrame1 mf =new MenuFrame1();
mf.setTitle("MenuFrame");
mf.setSize(300,200);
mf.setVisible(true);
}
a)
b)
c)
d)
d) new TextArea(200)
133) Which of the following creates a List with 5 visible items and multiple selection
enabled?
b) new List(true, 5)
d) new List(false,5)
a) show( )
b) setVisible( )
c) display( )
d) displayFrame( )
e) both a and b
a) True
b) False
a) True
b) False
a) Non-exclusive Checkboxes
b) Radio buttons
c) Choice
d) List
e) Both a and d
a) Window
b) Frame
c) Dialog
d) All of above
a) Panel
b) Applet
c) both a and b
d) only d
a) getPreferredSize( )
b) getPreferred( )
c) getRequiredSize( )
d) getLayout( )
141) Which layout should you use to organize the components of a container in a tabular
form?
a) CardLayout
b) BorederLayout
c) FlowLayout
d) GridLayout
142) What is the default layouts for a applet, a frame and a panel?
143) 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();
a) CheckboxMenuItem
b)Menu
c)MenuItem
d) All of above
a)setState(boolean)
b) setstate(boolean)
c)setEnabled(boolean)
d)setenabled(boolean)
a)A separator
c)A menu
d)A button
e)both a and c
Answer Key