Advance Java MCQ Ch1
Advance Java MCQ Ch1
Advance Java MCQ Ch1
1. AWT Means?
a) Abstract Windows Toolkit
b) Advanced Web Toolkit
c) Abstract Web Toolkit
d) Advanced Web Technology
7. Color class can create object of it using which of the following color
values?
a) RGB
b) RYB
c) CMY
d) HSB
11. How you can remove all the controls from the applet?
a) Using remove( ) method.
b) Using removeAll( ) method.
c) Using removeAllControls( ) method.
d) It is not possible to remove all controls using single method.
17. How can we copy the ‘List’s contents into ‘Choice’s contents
a) This is not possible.
b) Using copyInto( ) method of List
c) Directly assigning List object to Choice object.
d) Using copyFrom( ) method.
22. Which method is used to append the text at the end of TextArea?
a) append( )
b) add( )
c) appendAt( )
d) addAt( )
26. The correct constructor of Insets( ) which uses the values is…
a) Insets(int top, int left, int bottom, int right)
b) Insets(int bottom, int right, int top, int left)
c) Insets(int right, int top, int left, int bottom)
d) Insets(Dimesnion d1, Dimension d2)
28. The concept of the menu bar canbe implemented by using three java classes—
a. MenuBar
b. Menu
c. MenuItem
d. All of these
b. BorderLayout
c. GridLayout
d. CardLayout
e. All of these
31. In Java an event is an _______which specifies the change of state in the source.
a. Class
b. Object
c. Int
d. String
33. The classes and interfaces defined in AWT are contained within the ______
package.
a. java.awt.*
b. java.sql.*
c. java.io.*
d. java.int*
34. Java packages such as ________________ support the Event handling mechanism.
a. java.util
b. java.awt
c. java.awt.event
d. All of these
d. WindowListener, MouseListener
e. TextListener
f. All of these
37. 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
40. In Java, events are all the activities that occur between
a. The user
b. The applications
c. Both a & b
d. None of these
42. Positions the components into five regions:east, west, north, south, center
a. BorderLayout
b. CardLayout
c. GridLayout
d. FlowLayout
43. 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
Chapter 01 Introduction to AWT
47. The Component class and MenuComponent class are the ___________ which
represent the GUI components.
a. Subclasses
b. Superclasses
c. Both a & b
d. None of these
48. 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
49. 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
b. Superclass
c. Both a & b
d. None of these
d. Botttom-up
59. The __________ interface is used to handle the menu events
a. ContainerListener
b. FocusListener
c. ActionListener
d. WindowListener
60. 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
Maharashtra State Board of Technical Education
(A utonomous) (ISO 9001:2008) (ISO/IEC 27001:2005)
e-Exam Manage Questions for Advanced Java Programming (17625) for topic 1 Go Back to Subjects
Q To Fig Q Mar
Question Answer
No pic ure Type ks
2 Which are various AWT controls from following? 1 N R 1 Labels, Push buttons, Check boxes, Choice lists.
4 A checkbox is a control that consists of a ____________ 1 N R 1 Combination of a small box and a Label
23 AWT is used for creating a GUI in Java. AWT stands for 1 N R 1 Abstract Window Toolkit
33 By which method You can set or change the text in a Label? 1 N R 1 setText()
61 How can the Checkbox class be used to create a radio button in AWT? 1 N R 1 By associating Checkbox objects with a CheckboxGroup
62 How do you change the current layout managers for a container? 1 N R 1 Use the setLayout() method
65 How would you set the color of a graphics context called g to cyan? 1 N R 1 g.setColor(Color.cyan);
66 Identify the correct constructor of Font class? 1 N R 1 Font( String name, int fontstyle,int pointsize)
In applet, which of the following tag is used for accepting user defined
68 1 N R 1 Param
parameter?
69 In AWT Checkbox class is used to create __________ 1 N R 1 Checkbox and Radio buttons
73 In how many ways we can define the scrollbar? 1 N R 1 All of the above
86 List can be created for multiple selection by using following constructor. 1 N R 1 List(int num,boolean multiselect)
101 Select the proper constructor of FileDialog 1 N R 1 FileDialog(Frame parent, String boxName)
102 Select the proper syntax to addcomponent in an applet 1 N R 1 Component add(Component comoObj)
112 The CardLayout class defines the following constructors: 1 N R 1 CardLayout() // First Cardlayout(int hor, int ver) //second
The concept of the menu bar canbe implemented by using three java
114 1 N R 1 All of these
classes—
The default layout manager for the content pane of a swing based
117 1 N R 1 Border-Layout
applet is
120 The method setLabel can be used with what type of Object ? 1 N R 1 TextField.
121 The method ____gets the text of the button jtb is 1 N R 1 jtb.getText( )
122 the method _________ places a menu mu into a menu bar mb. 1 N R 1 mb.add(mu)
127 The string parameter to the JButton constructor 1 N R 1 tells what text will appear on the button
129 The syntax for drawRect() method is 1 N R 1 drawRect(int top, int left, int width, int height)
132 The various controls supported by swing are: 1 N R 1 all of the above
135 The _____________ class is used to create radio button in AWT 1 N R 1 CheckboxGroup
138 To create window with title bar which of the following class is used? 1 N R 1 Frame
144 To set title to the frame window___________ method is used. 1 N R 1 void setTitle(String str)
146 What are controls or components? 1 N R 1 Controls or components allow users to interact with application
148 What Are The Types of Dialogbox ? 1 N R 1 modal and Modeless Dialogbox
149 What are the variables defined in Dimension 1 N R 1 height and width
150 What Checkbox method allows you to tell if a Checkbox is checked? 1 N R 1 getState()
What does the following line of code do? TextField text = new
151 1 N R 1 Creates text object that can hold 10 columns of text.
TextField(10);
154 what is default layout manager for panels and applets 1 N R 1 FlowLayout
156 What is the difference between a TextArea and a TextField? 1 N R 1 A TextArea can handle multiple lines of text
157 What is the minimum and maximum of JProgressBar 1 N R 1 minimum -0 Maximum -100
160 What is use of second parameter in given constructor Label(String,int) 1 N R 1 sepcifies the alignment of text in label in terms of pixel
What methods are used to get and set the text label displayed by a
164 1 N R 1 getLabel( ) and setLabel( )
Button object?
170 Which abstract class is the super class of all menu related classes. 1 N R 1 MenuComponent
172 Which are the Alignment Constant of Label ? 1 N R 1 All The Above
175 Which AWT control is used for multi-line text entry? 1 N R 1 TextArea
179 Which class encapsulates a blank window upon which we can draw? 1 N R 1 Canvas
180 Which class is on the top of the AWT event hierarchy? 1 N R 1 java.awt.AWTEvent
Which class is used to create a pop-up list of items from which the user
181 1 N R 1 Choice
may choose?
184 Which class provides many methods for graphics programming? 1 N R 1 java.awt.Graphics
187 Which component in swing represents data in rows and columns? 1 N R 1 JTable
189 1 Y1 R 1 Label,TextField
190 which Container use a Border Layout as their default layout? 1 N R 1 All of the above
191 Which containers may have a MenuBar? 1 N R 1 Frame
193 Which h costructor creates a TextArea with 10 rows and 20 columns ? 1 N R 1 new TextArea(10 , 20 )
Which is correct method for adding button component into North region
195 1 N R 1 add(b1, BorderLayout.NORTH)
of border layout? Assume b1 as button object .
199 Which is the correct constructor for JProgressBar 1 N R 1 All of the above
200 Which is the correct constructor of GridLayout 1 N R 1 GridLayout(int numrows, int numcols)
202 Which is the method is used to count the number of items in the list 1 N R 1 getItemCount()
208 Which method gets the text associated with Label object jlbl? 1 N R 1 jlbl.getText()
211 Which method is used to change size and position of Components? 1 N R 1 void setBounds(int x,int y,int width,int height)
212 Which method is used to change the name of a menu item 1 N R 1 void setLabel(String newName)
216 Which method is used to set the dimensions of the window. 1 N R 1 void setSize(int newWidth, int newHeight)
217 Which method is used to set the layout of the Applet? 1 N R 1 setLayout();
218 Which method sets the size and position of a component 1 N R 1 setBounds()
227 which of the following class is Derived from Container Class? 1 N R 1 Panel
228 Which of the following class act as a super class in class hierachy? 1 N R 1 Component
230 Which of the following components does not have visible borders? 1 N R 1 Panel
232 Which of the following controls does not support interaction with user? 1 N R 1 Label
Which of the following creates a List with 5 visible items and multiple
233 1 N R 1 new List(5, true)
selection enabled?
239 Which of the following is not true about Dialog Boxes? 1 N R 1 Dialog boxes contains menu bars.
240 Which of the following is not true about Swing Components? 1 N R 1 Heavy weight components
241 Which of the following is not valid alignment constant for Label? 1 N R 1 MIDDLE
242 Which of the following is not valid constructor for JCheckBox? 1 N R 1 JCheckBox(String text, boolean selected, CheckboxGroup group)
243 Which of the following is not valid style constant for Font? 1 N R 1 NORMAL
246 Which of the following is true about AWT and Swing Component? 1 N R 1 AWT Components create a process where as Swing Component create a thread
248 Which of the following layout managers need to create a Panel? 1 N R 1 CardLayout
Which of the following method is use to add a button “b” to the south
251 1 N R 1 add(b,BorderLayout.SOUTH);
of the applet using BorderLayout?
252 Which of the following method is used to change the Label caption? 1 N R 1 setText(String s)
253 Which of the following method is used to retrive icon of JButton 1 N R 1 Icon getIcon()
257 Which of the following statements about GUI components is wrong ? 1 N R 1 The AWT classes are deprecated
Which of the following statements is for placing the frames upper left
258 1 N R 1 frame.setLocation(200,100)
corner to (200,100)?
260 Which of the follwing is constructor of Jtable? 1 N R 1 JTable(Object data[][], Object colHeads[])
261 Which of the method can be used to output a string in an applet? 1 N R 1 drawString()
Which of the method Choice class returns a string containing the name
262 1 N R 1 String getSelectedItem()
of the item.
264 Which Of these Compenent can be added to frame? 1 N R 1 All of the Above
268 Which of these methods can be used to output a string in an applet? 1 N R 1 drawString()
270 Which of these methods cannot be called on TextArea? 1 N R 1 String getItem(int index)
271 Which of these methods is used to setting the winwods dimension 1 N R 1 void setSize(Dimension new_size)
273 Which of these package is used for graphical user interface ? 1 N R 1 java.awt
275 Which one is the valid constructor of JCheckBox. 1 N R 1 JCheckBox(Sting s, Icon I, Boolean State)
276 Which one method is used to set the visibility of the frame? 1 N R 1 setVisible(true)
277 Which package use for import the swing components? 1 N R 1 javax.swing.*;
which type of button is belongs to a group such that only one button in
279 1 N R 1 CheckboxGroup
the group may be selected at one time?
280 Which of these events is generated when a button is pressed? 1 N R 1 B.) ActionEvent
281 Why are swing component termed as lightweight ? 1 N R 1 they do not depend on native platform
284 Window, frame and dialog use ________ as their default layout. 1 N R 1 BorderLayout
You Can set the alignment of the string within the label by calling
286 1 N R 1 setAlignment()
_______________________
290 _________is the Superclass of TextField and the TextArea classes: 1 N R 1 TextComponent
__________ is a Swing class that allows the user to enter a single line
292 1 N R 1 JTextField
of text.
295 __________ method is used to add the menubar on frame window. 1 N R 1 setMenuBar()
316 ………………………. method is used to lock text box components. 1 N R 1 setEditable(boolean flag)
Figure:-
320 The Jtable used to display data in form of? 1 N U 2 JTable object displays rows and columns of data.
//Identify the correct output for the given code. import java.awt.*;
import java.applet.*; /*<aaplet code="LabelDemo" width=300
height=200></applet>*/ public class MyApplet extends Applet { public
323 1 Y2 A 2
void init() { Label one = new Label("One"); Button submit = new
Button("Submit"); TextField enter = new TextField(); add(one);
add(submit); add(enter); } }
//Select the correct option for the following code. import java.awt.*;
import java.applet.*; import java.awt.event.*; /*<applet
code=scrolldemo width=200 height=300> </applet>*/ public class
scrolldemo extends Applet implements AdjustmentListener { Scrollbar
s1,s2,s3; TextField r,g,b; Color c; public void init() { s1=new
Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256); s2=new
Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256); s3=new
Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256); r=new TextField(5); g=new
325 TextField(5); b=new TextField(5); add(s1); add(r); add(s2); add(g); 1 N A 2 background with combination of r,g and b.
add(s3); add(b); s1.addAdjustmentListener(this);
s2.addAdjustmentListener(this); s3.addAdjustmentListener(this); }
public void adjustmentValueChanged(AdjustmentEvent ae) {
r.setText(Integer.toString(s1.getValue()));
g.setText(Integer.toString(s2.getValue()));
b.setText(Integer.toString(s3.getValue())); c=new
Color(s1.getValue(),s2.getValue(),s3.getValue()); setBackground(c); }
}
1.public class sample5 extends Applet 2.{ 3.public void init() 4.{
5.//CheckboxGroup cg=new CheckboxGroup(); 6.Checkbox c1,c2,c3,c4;
7.c1=new Checkbox("maths",true); 8.c2=new
328 1 N A 2 Line number 14
Checkbox("physics",false); 9.c3=new Checkbox("science",false);
10.c3=new Checkbox("computer",true); 11.add(c1); 12.add(c2);
13.add(c3); 14.add(c4); 15 .} 16. }
331 2. What is the purpose of JTable? 1 N U 2 JTable object displays rows and columns of data.
A JFrame supports three operations when the user closes the window.
336 1 N U 2 LOWER_ON_CLOSE
Which of the choices below is not one of the three:
337 A menu bar represents 1 N U 2 A list of menus which can be added to the top of a top-level window
A Swing component can be viewed based on what state it’s in, how it
338 looks, and what it does. This is known as the model-view- __________ 1 N U 2 Controller
model.
A toggle button looks just like a push button, but it acts differently
339 1 N U 2 it has two states: enabled and disabled
because _________________________..
348 By which method You can set or change the text in a Label? 1 N U 2 setText()
Choose the correct Program for the following output import javax.swing.JFrame; import javax.swing.JTree; import
javax.swing.SwingUtilities; import javax.swing.tree.DefaultMutableTreeNode; public
Figure:-
class TreeExample extends JFrame { private JTree tree; public TreeExample() {
//create the root node DefaultMutableTreeNode root = new
DefaultMutableTreeNode("Root"); //create the child nodes
DefaultMutableTreeNode vegetableNode = new
DefaultMutableTreeNode("Vegetables"); DefaultMutableTreeNode
355 1 Y1 A 2
fruitNode = new DefaultMutableTreeNode("fruits"); //add the child nodes
to the root node root.add(vegetableNode); root.add(fruitNode); //create the tree by
passing in the root node tree = new JTree(root); add(tree);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle("JTree
Example"); this.pack(); this.setVisible(true); } public static void main(String[]
args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new
TreeExample(); } }); } }
import java.applet.*; import java.awt.*; public class RadioButton1 { public static void
main(String arg[]) { Frame fm=new Frame("RedioButton Group"); Label
la=new Label("What is your choice:"); fm.setLayout(new GridLayout(0,1));
CheckboxGroup cg1=new CheckboxGroup(); fm.add(la); Checkbox cb1=new
357 1 Y1 U 2 Checkbox("MATH",cg1,true); Checkbox cb2=new
Checkbox("PHYSICS",cg1,false); Checkbox cb3=new
Checkbox("CHEMISTRY",cg1,false); Checkbox cb4=new
Checkbox("ENGLISH",cg1,false); fm.setVisible(true); fm.add(la);
fm.add(cb1); fm.add(cb2); fm.add(cb3); fm.add(cb4); } }
import java.awt.*; import java.applet.*; public class test11 extends Applet { public
void init() { TextField t1=new TextField(20); Checkbox c=new
362 1 Y1 A 2
Checkbox("a", true); Checkbox c1=new Checkbox("b" , false);
add(t1); add(c); add(c1); } }
370 1 Y1 U 2 Checkbox,TextArea,Button,Label
Consider following program and find the missing statement in the code
import java.awt.event.*; import java.awt.*; import java.applet.*; /*
<applet code=exp1.class width=200 height=200> </applet> */ public
class exp1 extends Applet { public void init() { add(new
371 1 N A 2 setLayout(new BorderLayout());
Button("TOP"),BorderLayout.NORTH); add(new
Button("BOTTOM"),BorderLayout.SOUTH); add(new
Button("RIGHT"),BorderLayout.EAST); add(new
Button("LEFT"),BorderLayout.WEST); } }
Consider following program and state how meny main menu and sub
menu displayed in output: import java.awt.*; public class MenuDemo {
public static void main(String args[]) { Frame f=new Frame("My
Frame"); f.setVisible(true); MenuBar mbr= new MenuBar();
f.setMenuBar(mbr); Menu filemenu=new Menu("File"); Menu
372 editmenu=new Menu("Edit"); Menu viewmenu=new Menu("View"); 1 N A 2 3 Main,3 Sub menu
mbr.add(filemenu); mbr.add(editmenu); mbr.add(viewmenu);
MenuItem new1=new MenuItem("New"); MenuItem open1=new
MenuItem("Open"); filemenu.add(new1); filemenu.add(open1);
new1.setEnabled(false); CheckboxMenuItem wordwrap=new
CheckboxMenuItem("WordWrap"); editmenu.add(wordwrap); }
Debug the following code and find out which statement contains error.
import java.awt.*; import java.awt.event.*; public class MenuDemo
extends Frame { MenuBar mb; Menu m1,m2; MenuItem i1,i2,i3,i4,i5,i6;
MenuDemo(String s) { super(s); mb=new MenuBar(); setMenuBar();
m1=new Menu("File"); m2=new Menu("Edit"); i1=new
MenuItem("New"); i2=new MenuItem("Open"); i3=new
384 1 N A 2 statement where setMenuBar() method is invoked
MenuItem("Exit"); i4=new MenuItem("Cut"); i5=new
MenuItem("Copy"); i6=new MenuItem("Paste"); m1.add(i1);
m1.add(i2); m1.add(i3); m2.add(i4); m2.add(i5); m2.add(i6);
mb.add(m1); mb.add(m2); setSize(500,500); } public static void
main(String args[]) { MenuDemo m=new MenuDemo("MenuFrame");
m.setVisible(true); } }
Debug the following code and find which statement contains error.
import javax.swing.*; import java.awt.*; public class
JRadioButtonDemo extends JApplet { JRadioButton r1,r2,r3; Container
c; public void init() { c=getContentPane(); c.setLayout(new
FlowLayout()); r1=new JRadioButton("Red"); r2=new
385 1 N A 2 Error in statement to create button group i.e. JRadioButtonGroup
JRadioButton("Green"); r3=new JRadioButton("Blue");
JRadioButtonGroup b=new JRadioButtonGroup ();
b.add(r1);b.add(r2);b.add(r3); c.add(r1);c.add(r2);c.add(r3); } } /*
<applet code=JRadioButtonDemo.class width=500 height=500>
</applet>*/
For the below code, how is a JTable object created? String[] colHeads
403 = { "Name", "Extension", "ID#" }; Object[][] data = {{ "Gail", "4567", 1 N U 2 JTable jt=new JTable(data,colHeads);
"865" },{ "Ken", "7566", "555" }};
Give proper command to compile & run following program code? import
java.applet.*; import java.awt.*; /* <applet code="A1" height="300"
405 width="300"> </applet> */ public class A1 extends Applet { public void 1 N A 2 C:\javac A1.java C:\appletviewer A1.java
paint(Graphics gr) { gr.drawString("Welcome to JAVA ",50,100);
setBackground(Color.cyan); } }
Given the following code import java.awt.*; public class SetF extends
Frame { public static void main(String argv[]) { SetF s = new SetF();
406 1 N A 2 s.setBackground(Color.pink);
s.setSize(300,200); s.setVisible(true); } } How could you set the frame
surface color to pink
How many components are used for form validation i.e input username
407 1 N U 2 2 Label,1 Button,2 Textfield
and password
409 How to add image on button 1 N A 2 ImageIcon ii = new ImageIcon(“India.gif”); JButton Jb= new JButton(“ok”,ii);
411 1 Y1 A 2 JButton,ScrollPane
Identify controls used in following output
Figure:-
414 1 Y1 U 2 GridLayout
415 Identify proper syntax from following options of TextArea constructor 1 N U 2 TextArea(int numlines, int numChars)
Identify the code for the output given below.
Figure:-
If user does not set size of frame then in output size of frame is _____
421 1 N U 2 0,0
width ______ height
In the applet window a user wants to arrange all component one after
430 1 N U 2 setLayout(new FlowLayout());
another Which statement will work efficiently
433 Is it possible to change display character of TextField?How? 1 N U 2 Yes,by using setEchoChar() method.
434 java Applets are used to create ……………………Applications 1 N A 2 both (a) and (b)
fig(a)-TextField,fig(b)-Button,fig(c)-Label,fig(d)-List,fig(e)-CheckBoxGroup,fig(f)-
435 1 Y1 U 2
checkbox,fig(g)-Choice
436 Modification of the text can be controlled by 1 N U 2 setEditable()
Multiple layouts in the single conainer can be created with the help of
437 1 N U 2 Panel
_______________
Observe the following program and point out which statement contains
error. importjava.awt.*; importjavax.swing.*; /* <applet
code="JTableDemo" width=400 height=200> </applet> */ public class
JTableDemo extends JApplet { public void init() { Container
contentPane = getContentPane(); contentPane.setLayout(new
BorderLayout()); final String[] colHeads = { "emp_Name", "emp_id",
"emp_salary" }; final Object[][] data = { { "Ramesh", "111", "50000"
443 1 N A 2 Error in statement in which JScrollPane is created
}, { "Sagar", "222", "52000" }, { "Virag", "333", "40000" }, { "Amit",
"444", "62000" }, { "Anil", "555", "60000" }, }; JTable table = new
JTable(data,colHeads ); int v =
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPanejsp = new JScrollPane(table,,h,v); contentPane.add(jsp,
BorderLayout.CENTER); } }
Observe the image shown below. S1Q42 Which AWT component will
the image as shown
Figure:-
444 1 Y1 A 2 CheckboxGroup
Picture is a ________________
Figure:-
445 1 Y1 U 2 CheckboxMenuItem
Point out missing word in syntax in given code import java.awt.*;
import java.awt.event.*; public class demo extends Frame { public
static void main(String args[]) { Button b; GridLayout cr=
GridLayout(3,4,5,10); Frame f=new Frame("GRIDLAYOUT EXAMPLE");
446 f.setLayout(cr); f.add(new Button("1")); f.add(new Button("2")); 1 N U 2 new
f.add(new Button("3")); f.add(new Button("4")); f.add(new
Button("5")); f.add(new Button("7")); f.setSize(300,400);
f.setVisible(true); } }
Say that a Frame contains three Panels. Could each Panel have a
448 1 N U 2 Yes---each one can use setLayout() with any layout manager
different layout manager?
450 Select correct statement to add component in south region. 1 N U 2 add(component obj,BorderLayout.SOUTH);
import java.awt.*; import java.applet.*; public class choice11 extends Applet { public
void init() { Choice os=new Choice(); os.add("wnn18"); os.add("wnn
451 1 Y1 A 2 xp"); os.add("wnn nt"); os.add("win 2000"); add(os); }
} /*<applet code="choice11" height=200 width=300>
</applet>*/
Select the proper output for following code import java.awt.*; import
java.applet.*; public class DemoBorderLayout extends Applet { Button
b1,b2,b3,b4,b5; public void init() { BorderLayout b=new
BorderLayout(20,30); setLayout(b); b1=new Button("Top"); b2=new
Button("Right"); b3=new Button("Bottom"); b4=new Button("Left");
473 1 Y2 A 2 S1Q42O2
b5=new Button("Center"); add(b1,BorderLayout.NORTH);
add(b2,BorderLayout.EAST); add(b3,BorderLayout.SOUTH);
add(b4,BorderLayout.WEST); add(b5,BorderLayout.CENTER); } } /*
<applet code="DemoBorderLayout.class" width=350 height=300>
</applet>*/
474 1 Y1 U 2 Buttons,FlowLaout.RIGHT
476 Show a single line of code that will convert char ch into String s 1 N A 2 String s=””+ch;
State the method that will be used so as to display the password as '?'
in the output shown in S1Q43
Figure:-
478 1 Y1 A 2 setEchoChar('?')
state the output and assume suitable data import java.awt.*; import
java.applet.*; class Demo extends Applet { CheckBox c1,c2; public void
479 1 N U 2 label of c2 will print
init(){ C1=new CheckBox(“awt”); C2=new CheckBox();
System.out.println(c2.getLabel()); } }
1. Create a JTabbedPane object 2. Call addTab() to Add a tab to the pane 3.Repeat
481 Steps for Adding TabbedPane Control 1 N U 2
Step 2 for each Tab 4. Add the Tabbed Pane to the conte
483 Swing components are light weight because: 1 N A 2 Swing components are platform independent.
485 Tabbedpane Layout can be changed using: 1 N U 2 Mentioning layout in constructor only.
The code Code will produce how many buttons: public class
JScrollPaneDemo extends JApplet { public void init() { // Get content
pane Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout()); JPanel jp = new
JPanel(); jp.setLayout(new GridLayout(20, 20)); int b = 0; for(int i = 0; i
486 < 20; i++) { for(int j = 0; j < 20; j++) { jp.add(new JButton("Button " + 1 N A 2 400 Buttons
b)); ++b; } } // Add panel to a scroll pane int v =
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(jp, v, h); // Add scroll pane to the
content pane contentPane.add(jsp, BorderLayout.CENTER); } }
487 The constructor JCheckBox(true, “YES”) suggests that – 1 N U 2 Checkbox is selected and displays the string “YES” on it.
488 The default horizontal and vertical gap in FlowLayout is….. 1 N U 2 5 Pixel
490 1 Y1 U 2 BorderLayout
491 1 Y1 U 2 CardLayout
493 The layout manger that shows how words flow in a text editor?Use 1 N U 2 Flow
494 The main difference between model and models dialog box is 1 N U 2 When box is active input focus can not be directed to another window
The method _______ assigns the name Result to the Text of variable
495 1 N A 2 jlbl.setText("Result")
jlbl.
496 The method __________ separates menu items in a menu mu. 1 N A 2 mu.addSeparator()
502 To implement a single –line text area entry area, Use? 1 N A 2 TextField
503 To place any component in AWT/Swing which method will be used 1 N U 2 setBounds(int x,int y,int height,int width)
To set new font object with size 48 , name: Serif , Style PLAIN, what
will be the statement from the following
Figure:-
508 1 Y1 U 2 Label,Checkbox,checkboxGroup,FlowLayout
What code should be added so that we can get following Code? import
java.awt.*; import java.applet.*; import java.awt.event.*; /*<applet
code=SignIn.class width=400 height=400></applet>*/ public class
SignIn extends Applet implements ActionListener { TextField t1,t2;
Button b1; Label l; public void init() { t1=new TextField(20); t2=new
TextField(20); b1=new Button("Sign In"); l=new Label(""); "); add(t1);
add(t2); --------------------- add(b1); ---------------------- add(l); } public
void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) {
String msg=t1.getText(); String msg1=t2.getText();
if(msg.equals("Admin")&&msg1.equals("Admin")) { l.setText("Correct
509 Password"); } else { l.setText("Incorrect Password"); } } } }
1 Y1 A 2 Both A & B
Figure:-
What code should be added so that we can get following Code? import
java.awt.*; import java.awt.event.*; class WindowCloseDemo extends
Frame { Button exit; WindowCloseDemo() { exit=new Button("Exit");
add(exit); WindowClose w=new WindowClose();
addWindowListener(w); setTitle("Window"); setSize(400,300);
setVisible(true); } public static void main(String []cd) {
WindowCloseDemo wcd=new WindowCloseDemo(); } } class
WindowClose extends WindowAdapter { public void
windowClosing(WindowEvent we) { System.exit(1); } }
Figure:-
511 What code would you use to construct a 24-point bold Calibri font? 1 N U 2 new Font("Calibri", Font.BOLD,24);
515 1 Y1 U 2 Button,Checkbox,RadioButton
519 1 Y1 U 2 JPasswordField,JComboBox,ToolTipText,JTextArea
What components will be needed to get following output?
Figure:-
523 1 Y1 U 2 Label,textfield,Button
531 What is Purpose of Jtree ? 1 N U 2 A tree is a component that presents a hierarchical view of data
532 What is purpose of default constructor of Scrollbar( ) class? 1 N U 2 To create vertical Scrollbar
538 1 Y1 U 2 FlowLayout
What is the length of the application box made by this program? import
539 java.awt.*; import java.applet.*; public class myapplet extends Applet 1 N A 2 Compilation Error
{ Graphic g; g.drawString("A Simple Applet", 20, 20); }
546 What is the purpose of JTabbedPane? 1 N U 2 JTabbedPane manages a set of components of linking them with tabs.
547 What is the purpose of ScrollPane 1 N U 2 ScrollPane Displays component in a rectangular area
549
What is the purpose of ToggleButton? 1 N U 2 On or Off Switch
What is the result of executing the following Java class: import java
.awt.*; public class FrameTest extends Frame { public Frame Test() {
550 add (new Button("First")); add ( new Button( "Second")); add (new 1 N A 2 Only the third button is diplayed .
Button ("Third")); pack() ; setVisible(true); } public static void main (
String args [] { new Frame Test ();}}
552 What is the use of setEchoChar() method? 1 N U 2 to create password in symbol form
553 What is the use of setLayout() method 1 N U 2 To install a new layout manager
555 What is use of GridLayout Manager ? 1 N U 2 lays out components in a two-dimensional grid
What will be the order of four items added Choice c1 = new Choice();
563 c1.add("First"); c1.addItem("Second"); c1.add("Third"); 1 N U 2 First,Second,Lastadded,Third
c1.insert("Lastadded",2);
Where g is a graphics instance what will the following code draw on An arc bounded by a box of height 50, width 50, with a centre point of 45,90 starting
568 1 N A 2
the screengfillArc(45,90,50,50,90,180); at an angle of 90 degrees traversing through 180 degrees clockwise
570 1 Y1 A 2 Yes
571 which abstract class is the super class of all menu related classes? 1 N U 2 MenuComponent
Which among the below is not the method applicable for Button in
572 1 N U 2 setDisableIcon()
swing
573 Which among the following is not correct regarding dialog? 1 N U 2 Use of Dialog effects the working of Application
574 Which among the following is the feature of Jtable 1 N U 2 all of these
575 Which are the valid ways to create DataInputStream streams? 1 N A 2 new DataInputStream(new FileInputStream("in.dat");
576 Which are true about the Container class? 1 N U 2 All of the above
577 which AWT complonents are used to produce given output? 1 N U 2 Button, Label, TextField, TextArea
581 which class provides method for accessing a font's properties? 1 N U 2 FontMerices
585 1 Y1 U 2 JScrollPane,Icon
Which Componenets and layout manager are used in following output
Figure:-
586 1 Y1 U 2 Buttons,Borderlayout
591 Which Component subclass is used for drawing and painting? 1 N U 2 Canvas
596 1 Y1 A 2 Label,Choice
601 1 Y1 U 2 Label,TextArea,Button
604 1 Y1 U 2 Checkbox,Label
605 1 Y1 U 2 JButton,JTextField
609 1 Y1 U 2 Label,TextField,Button
Which components are used in the following output?
Figure:-
610 1 Y1 U 2 Label,TextField,Button
615 Which components provide support for two-state buttons? 1 N U 2 JCheckBox, JRadioButton
616 Which constructor creates a TextArea with 10 rows and 20 columns? 1 N U 2 new TextArea(10, 20);
617 1 Y1 U 2 Jtable(2,3)
618 Which control is a combination of text field and dropdown list? 1 N U 2 combo boxes
619 Which Gridlayout class constructor creates single column grid Layout? 1 N U 2 GridLayout()
620 Which is componant in AWT which contain another componant? 1 N U 2 Container
Which is the layout manger that occupies the same size on the
622 1 N A 2 Grid
window?
625 1 Y1 U 2 FlowLayout
626 1 Y1 U 2 GridBagLayout
627 1 Y1 U 2 BorderLayout
628 1 Y1 U 2 GridLayout
629 1 Y1 U 2 BorderLayout
Which layout manager can be used to get the following output?
Figure:-
630 1 Y1 U 2 GridLayout
631 1 Y1 U 2 GridLayout
635 Which method is used to display title on titlebar of Frame? 1 N U 2 setTitle(String title)
638 1 Y1 U 2 drawString("HelloWorld",30,30)
Which method of the component class is used to set the position and
639 1 N U 2 setBounds()
the size of a component?
Which method specifies that the text and icon are horizontally aligned
641 1 N U 2 jbt.setHorizontalTextPosition(JButton.RIGHT)
to the right in the button jbt.
642 1 Y1 U 2 a)drawPolygon(),fillPolygon()
All the methods in the JButton class are inherited from the javax.swing.AbstractButton
643 Which of following is true? 1 N U 2
class
647 Which of the following constructor creates a Checkbox? 1 N U 2 Checkbox(String str, boolean s, null)
Which of the following create a list with five visible items and multiple
648 1 N U 2 new List(5,true)
selection enabled?
Which of the following creates a List with 3 visible items and multiple
649 1 N U 2 new List(3,false)
mode selection disabled?
Which of the following method adds item "I" to the List with
654 1 N U 2 addItem(“I”)
deprecation warnings at the end of List?
Which of the following method use to get the text or caption of the
656 1 N U 2 jbt.getText()
button jbt?
660 Which of the following options is correct about Layout Manager 1 N U 2 Both B and C
Which of the following statement is for placing the frames upper left
661 1 N A 2 frame.setLocation(200,100)
corner to (200,100)
Which of these classes can be added to any Container class, using the
666 1 N U 2 Button
add method defined in Container class ?
667 Which of these events will be notified if scroll bar is manipulated? 1 N U 2 AdjustmentEvent
668 Which of these is not a constructor of the FileDialog? 1 N U 2 FileDialog(Frame parent,int how)
670 Which of these methods can be used to determine the type of event? 1 N U 2 getID()
671 Which of these methods can be used to know which key is pressed 1 N U 2 getModifier()
672 Which of these methods returns the class of the object? 1 N U 2 getClass()
674 Which one is the constructor of the Jtable? 1 N U 2 JTable(Object data[ ][ ], Object colHeads[ ])
Create a Jtree Object, Create a JScrollPane object, Add the tree to the scrollpane and
675 Which option is correct to adding Jtree in an Applet? 1 N U 2
Add the scroll pane to the content pane of the applet.
688 1 Y1 U 2 c)Jtree
691 Why we need to write static keyword to main method ? 1 N U 2 To create single copy
import java.awt.*; public class Butt extends Frame { public static void main(String
argv[]) { Butt MyBut=new Butt(); } Butt() { setLayout(new
692 1 Y1 A 2 FlowLayout(FlowLayout.CENTER)); Button HelloBut=new Button("Hello");
Button ByeBut=new Button("Bye"); add(HelloBut); add(ByeBut);
setSize(300,300); setVisible(true); } }
Program: CO5I Course: Advanced Java Programming (22517) Course Co-ordinator: Mrs.Chavan P.P.
Unit I- Abstract Window Toolkit
Question Bank
1 Give the Abbreviation of AWT : Applet WindowingToolkit Abstract Window Toolkit Absolute Windowing Toolkit None of these
8 Applet can be embedded in _____________. HTML document word document gif file rtf file
11 Executable applet is _________ .applet file .java html .java file .class file
12 Java applet are used to create_________applications. graphical user interactive both (a) and (b) none of the above
16 Which of the following class is derived from the container class? Component Panel MenuComponent List
Which of these classes can be added to any Container class, using the add
19 Button CheckboxMenuItem Menu MenuBar
method defined in Container class?
These two ways are used to create a Frame 1. By creating the object of
22 TRUE FALSE
Frame class (association) 2. By extending'Prame class (inheritance)
23 The title of the frame can be set in AWT using the method. setHeading setTitle CreateTitle Settitle
Which are passive controls that do not support any interaction with the
24 Choice List Label Checkbox
user?
29 The most commonly used layout managers are_____ FlowLayout GridLayout BorderLayout All of these
30 The subclasses of Window are Dialog Frame Both a & b None of these
31 Default layout manager for subclasses of window is _ cardlayout GridBaglayout Frame BorderLayout
32 Each menu is associated with a _________ list of menu items: Checkbox Drop-down Choice None of these
Which class can be used to represent a checkbox with a textual label that
33 MenuBar MenuItem CheckboxMenuItem Menu
can appear in a menu ?
34 Which abstract class is the super class of all menu related classes? MenuComponent MenuBar MenuItem CheckboxMenuItem
35 Menu items are added to ______ Menus MenuBar Frame Both a & b
36 Dialog box does not have minimize and maximize button TRUE FALSE
A dialog box is referred to as modeless if the user does not have to close it
37 TRUE FALSE
in order to continue using the application that owns the dialog box.
38 The __ class displays a dialog window from which the user can select a file. Dialog FileDialog File None of these
new TextArea(new
40 Which constructor creates a TextArea with 10 rows and 20 columns? Rows(10), new new TextArea(20, 10). new TextArea(10, 20). new TextArea(200).
columns(20)).
Which of the following creates a List with 5 visible items and multiple
41 new List(true, 5). new List(5, true). new List(5, false). new List(false,5).
selection enabled?
44 Which of the following components allow multiple selections? Combo box. Radio buttons. Choice. List.
45 Which method is method to set the layout of a container? startLayout( ). initLayout( ). layoutContainer( ). setLayout( ).
48 Which of the following may contain a menu bar? A panel. .A frame. An applet. A menu bar.
52 Which object is needed to group Checkboxes to make them exclusive? RadiobuttonGroup. CheckboxGroup. ControlGroup. GroupCheckbox
Arranges the components as a deck of cards such that only one component
54 BorderLayout CardLayout GridLayout FlowLayout
is visible at a time
55 __________ creates a dropdown list of textual entries Choice Checkbox Textbox TextComponent