Sunday, May 26, 2019

Chapter 2(MCQ:101-200)

Chapter 2

The modern approach to handling events is based on the delegation event
model, which defines standard and consistent mechanisms to generate and
process events. Its concept is quite simple: a source generates an event and
sends it to one or more listeners. In this scheme, the listener simply waits until
it receives an event. Once received, the listener processes the event and then returns. The advantage of this design is that the application logic that processes
events is cleanly separated from the user interface logic that generates those
events. A user interface element is able to “delegate” the processing of an
event to a separate piece of code.

 For MCQ 1-100 Chapter 2

101 Which event is generated by List = Both A and B

102 Which Event is generated by Scrollbar class? = AdjustmentEvent

103 Which is a method of the MouseMotionListener Interface? = public void mouseDragged(MouseEvent )

104 Which is not the correct listener = TextAreaListener

105 Which is the interface of MouseEvent class ? = MouseListener

106 Which Listener handles all List related Events = ItemListener

107Which method does display the message whenever there is an item selection or deselection of
the CheckboxMenuItem menu?= itemStateChanged method.

108 Which method is applicable if alphanumeric key is pressed. = keyTyped

109 Which method is defined when action event is occurs? = actionPerformed()

110 Which Method Is used to register a mouse Motion Listner = addMouseMotionListener()

111 Which method used for return for mouse co-ordinate ? = getX () ,getY()

112 Which methods are defined by ComponentListener = void componentHidden(ComponentEvent obj)

113 Which of the following are correct event handling methods = mousePressed(MouseEvent e){}

114 Which of the following are true? = Both A and B

115 Which of the following componant generate ActionEvent? = none

116 Which of the following component can generate ItemEvent? = CheckBoxMenuItem

117 Which of the following is not event class is Java? = ClickEvent

118 Which of the following is the highest class in the event delegation class hierarchy? = java.util.EventObject

119 Which of the following is the legal adapter classes in java. = MouseAdapter

120 Which of the following Listeners have their Adapter class = WindowListener

121 Which of the following method is used to register a listener to a button ? = addActionListener(ActionListener obj)
122 Which of these event is generated when a button is pressed? = ActionEvent

123Which of these methods can be used to obtain the command name for invoking ActionEvent
object?= getActionCommand()

124 Which of these a AdapterClass = KeyAdapter class

125 Which of these adapter class from follwing? = MouseAdapter

126 Which of these are constants defined in Window Event class = All the Above

127Which of these constant value will change when the button at the end of scroll bar was clicked
to increase its value?
= UNIT_INCREMENT

128 Which of these event is generated when computer gains or loses input focus? = FocusEvent

129 which of these event will be notified if scrollbar is manipulated? = AdjustmentEvent()

130 Which of these events is generated when a window is minimized? = Both a and b

131 Which of these events is generated when the component is added or removed? = ContainerEvent

132 Which of these events will be generated if we close an Frame's window? = WindowEvent

133 Which of these interfaces define a method actionPerformed()? = ActionListener

134 Which of these is super class of WindowEvent class? = ComponentEvent

135 Which of these is superclass of all Adapter classes? = Applet

136 Which of these methods are used to determine the type of adjustment event? = getAdjustmentType()

137 Which of these methods are used to register a mouse motion listener? = addMouseMotionListener().

138 Which of these methods can be used to know the degree of adjustment made by the user? = getValue()

139 Which of these methods is defined in MouseMotionAdapter class? = mouseDragged()

140 Which of these methods is used to get x coordinate of the mouse = getX()

141 Which of these methods is used to get Y coordinate of the mouse? = getY()

142 Which of these methods is used to know the full URL of an URL object? = getHOst()

143 Which of these methods is used to obtain the object that generated a ComponentEvent. = getContainer()

144 Which of these methods is used to obtain the object that generated a WindowEvent? = getWindow()

145 Which of these methods will be invoked if a character is generated? = keyTyped()

146 Which of these methods will respond when you click any button by mouse? = All of the mentioned

147 Which of these methods will respond when you click any button by mouse? = All of these

148 Which of these not a constants defined in ComponentEvent class? = COMPONENT_SIZED

149 Which two parameters are required for JTable constructor to create a table? = Data array and Column Headings

150 windowEvent is a subclass of ________________________ = ComponentEvent()

151 _______ generates action events when an item is double-clicked. = List

152__________is generated when checkbox is clicked, list item is clicked, choice selection is made
or checkable menu item is selected or deselected. = ItemEvent

153___________class provides an empty implementation of all methods in an Event Listener
interface?= Adapter
154 _________________generates an event and sends it to one or more listeners. = Event Source

155ActionEvent: It indicates the component-defined events occurred b)MouseEvent: Events
generated during the mouse operation for the object c) FocusEvent:This class indicates about
the focus where the focus has gained or lost by the object. d) KeyEvent: It is generated When
key is pressed
2 Y2 U 2 All a,b,c and d are correct

156For the following code select the method that can be used to handle event.
importjava.awt.event.*; import java.awt.*; importjava.applet.*; public class checkbackg extends
Applet implements ItemListener { Checkbox m1,m2,m3; public void init() { m1=new
Checkbox("A"); m2=new Checkbox("B"); m3=new Checkbox("C"); add(m1); add(m2); add(m3);
m1.addItemListener(this); m2.addItemListener(this); } public void
__________________(ItemEvent ie) { if(ie.getSource()==m1) setBackground(Color.red);
if(ie.getSource()==m2) setBackground(Color.green); } } /*<applet code=checkbackg.class
height=150 width=150> </applet>*/
= itemStateChanged(ItemEvent ie
)
157 1)For Key events, KeyEvent class is used 2)For Mouse motion events, MouseEvent class is used
3)For For Component events, CoumponentEvent class is used 4)For Window events, WindowE
class is used
= 1,2,3 are true
1. What will be the output of the following code? import java.awt.*; import java.applet.*; import

158java.awt.event.*; public class adm extends Applet { public void init() {
addMouseMotionListener(new mma1(this)); } } class mma1 extends MouseAdapter { adm a;
public mma1(adm a) { this.a=a; } public void mouseDragged(MouseEvent me) {
a.showStatus("mouse dragged"); } } /*<applet code="adm" width=500 height=500>
</applet>*/
2 Y2 U 2 S1-chapter2(Q1.C).jpg

159.Which line of code is missing in following code and error statement code line import java.awt.*;
import java.awt.event.*; import java.applet.*; /*<applet code="KeyEventDemo.class"
width=400 height=400> </applet>*/ public class KeyEventDemo extends Applet implements
_____________ { String msg=""; public void init() { addKeyListener(this); } public void
keyPressed(KeyEvent e) { showStatus("Key Down"); int key=e.getKeyCode(); repaint(); } public
void keyTyped(KeyEvent e) { msg+=e.getKeyChar(); repaint(); } public void paint(Graphics g) {
g.drawString(msg,10,20); } }
=
KeyListener and public void keyReleased(KeyEvent e) {
showStatus(&quot;Key up&quot;); }

160 What will happen when you attempt to compile and run the following code? import
java.awt.*; import java.awt.event.*; public class mouseClick extends Frame implements
MouseListener{ public static void main(String argv[]){ mouseClick s = new MClick(); } MClick(){
this.addMouseListener(this); } public void mouseClicked(MouseEvent e){
System.out.println(e.getWhen()); } }
= Error not override MouseListener methods ,class name not found

161. Which statement is incorrect or missing in the following code import java.awt.*; import
java.awt.event*; import javax.swing.*; public class radio extends JApplet implements
ActionListener { pulic void init() { c.setLayout(new FlowLayout()); JRadioButton b1=new
JRadioButton("Red"); b1.addActionListener(this); c.add(b1); JRadioButton b2=new
JRadioButton("Green"); b2.addActionListener(this); c.add(b2); JRadioButton b3=new
JRadioButton("Blue"); b3.addActionListener(this); c.add(b3); ButtonGroup bg=new
ButtonGroup(); bg.add(b1); bg.add(b2); bg.add(b3); } public void actionPerformed(ActionEvent
e){ setBackground(e.getActionCommand()); } }
= Container c=getContentPane();

162A Frame's background color is set to Color.Yellow, and a Button's 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?
= Color.Yellow.
163 A Java exception is an instance of __________. 2 N U 2 Throwable

164 Abstract Methods of MouseMotion Listener Interface. = mouseMoved(MouseEvent) mouseDragged(MouseEvent)

165 Action event is applied on 2 N U 2 Button, TextField, List, Menu

166 Adapter classes are similar to EventListener interfaces? = True

167Add the missing statement.. import java.awt.*; import java.awt.event.*; import java.applet.*; /*
<applet code="ButtonDemo" width=250 height=150> </applet> */ public class ButtonDemo
extends Applet implements ActionListener { String msg = ""; Button yes, no, maybe; public void
init() { yes = new Button("Yes"); maybe = new Button("Undecided"); add(yes); add(no);
add(maybe); yes.addActionListener(this); no.addActionListener(this);
maybe.addActionListener(this); } public void actionPerformed(ActionEvent ae) { String str =
ae.getActionCommand(); if(str.equals("Yes")) { msg = "You pressed Yes."; } else
if(str.equals("No")) { msg = "You pressed No."; } else { msg = "You pressed Undecided."; }
repaint(); } public void paint(Graphics g) { g.drawString(msg, 6, 100); } }
= no=new Button(&quot;NO&quot;)

168After inserting which statement in following program, output window will be closed when close
button is clicked import java.awt.event.*; import java.awt.*; class Demo extends Frame {
Demo() { setSize(500,500); setVisible(true); setTitle("My Window"); } public static void
main(String args[]) { new Demo(); } } class AdapterDemo extends WindowAdapter { Demo d1;
AdapterDemo(Demo d) { d1=d; } public void windowClosing(WindowEvent we) { d1.dispose(); }
}
= addWindowListener(AdapterDemo(this));

169 An event adapter can be implemented using ___________. 2 N U 2 All of Above

170 An event is generated when internal stae of event source is________ = changed
Analyse the following code and Find out errors. import java.awt.*; import java.applet.*; import
java.awt.event.*; /*<applet code="Demo" width=200 height=80> </applet>*/ public class
Demo extends Applet implements ItemListener { public void init() { Label jlb1=new Label("

171 Select Color:"); Choice ch=new Choice(); ch.addItem("Red"); ch.addItem("Green");
ch.addItem("Blue"); TextField jtf1=new TextField(12); add(jlb1); add(ch); add(jtf1);
ch.addItemListener(this); } public void itemStateChanged(ItemEvent ie) { String s=
(String)ie.getItem(); jtf1.setText(s); } }
= Error is in the statement String s=(String)ie.getItem();

172Analyse the following code and find out missing statement. import javax.swing.*; import
javax.swing.tree.*; public class TreeDemo extends JFrame { public static void main(String args[])
{ TreeDemo frame = new TreeDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultMutableTreeNode root = new
DefaultMutableTreeNode("Root"); DefaultMutableTreeNode mercury = new
DefaultMutableTreeNode("Mercury"); root.add(mercury); DefaultMutableTreeNode venus = new
DefaultMutableTreeNode("Venus"); root.add(venus); DefaultMutableTreeNode mars = new
DefaultMutableTreeNode("Mars"); root.add(mars); JTree tree = new JTree(root); JScrollPane
scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 150); frame.setVisible(true); } }
= missing package statement

173Analyse the following code and select missing statement. import java.awt.*; import
java.applet.*; /*<applet code="Demo" width=200 height=80> </applet>*/ public class Demo
extends Applet implements ItemListener { TextField jtf; List city; public void init() { city=new
List(4); city.addItem("Pune"); city.addItem("Mumbai"); city.addItem("Nagpur");
city.addItem("Kolhapur"); city.addItem("Solapur"); jtf=new TextField(12); add(jtf); } public void
itemStateChanged(ItemEvent ie) { String s=city.getSelectedItem(); jtf.setText(s); } }
= All of the above

174Analyze the following code import javax.swing.*; import javax.swing.border.*; import
java.awt.*; public class BorderTest extends JFrame{ public BorderTest(){ Border border=new
TitledBorder("MyButton"); JButton b1=new JButton("Ok"); JButton b2=new JButton("Cancel");
b1.setBorder(border); b2.setBorder(border); add(b1,BorderLayout.NORTH);
add(b2,BorderLayout.SOUTH); } public static void main(String args[]){ JFrame f=new
BorderTest(); f.setSize(200,100); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true); } } What will be the output of the above code?
= Two buttons displayed with the same border
.
175Analyze the following code: import javax.swing.*; import java.awt.*; public class Test extends
JFrame { public Test() { setLayout(new FlowLayout()); add(new JButton("Java")); add(new
JButton("Java")); add(new JButton("Java")); add(new JButton("Java")); } public static void
main(String[] args) { // Create a frame and set its properties JFrame frame = new Test();
frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true); } }
2 N U 2 Four buttons are displayed with the same text &quot;Java&quot;.

176ButtonGroup bg = new ButtonGroup(); is used to create group of
_________________________
= RadioButton

177Choose correct fig. as ouput for given code import java.awt.*; import java.applet.*; import
java.awt.event.*; public class addition2 extends Applet implements ActionListener { TextField t1;
TextField t2; TextField t3; Button b; {Label num1=new Label ("Addition of two numbers"); Label
num2=new Label("Enter First no in text field"); Label num3=new Label("Enter Second no in text
field"); t1=new TextField(); t2=new TextField(); t3=new TextField(); b=new Button("add");
setLayout(new GridLayout(4,2)); add(num1); add(t1); add(num2); add(t2); add(num3); add(t3);
add(b); b.addActionListener(this); } public void actionPerformed(ActionEvent ae)
{if(ae.getSource()==b) { int n1=Integer.parseInt(t2.getText()); int
n2=Integer.parseInt(t3.getText()); int sum=n1+n2; t1.setText(Integer.toString(sum)); } } } /*
<applet code="addition1" height=200 width=300> </applet>*/
2 Y2 A 2

178Choose the correct missing statement from the given code import java.awt.*; import
java.applet.*; import java.awt.event.*; public class eventdemo2 extends Applet implements
ActionListener { TextField t1,t2; Button b1; public void init() { t1=new TextField(5); t2=new
TextField(5); b1=new Button("FACTORIAL"); add(t1); add(t2); add(b1); } public void
actionPerformed(ActionEvent a) { if(a.getSource()==b1) { int fact=1; int
n1=Integer.parseInt(t1.getText()); while(n1!=0) { fact=fact*(n1); n1=n1-1; }
t2.setText(Integer.toString(fact)); } } } /* <applet code=eventdemo2.class width=250
height=200> </applet> */
= b1.addActionListener(this);
Choose the correct option for the given code import java.awt.*; import java.awt.event.*; import
java.applet.*; public class DemoE extends Applet { public void init() { Button b=new The program will display &quot;Button clicked &quot; message in status
179 Button("Click"); b.addMouseListener(new MouseAdapter() { public void
mouseClicked(MouseEvent me) { showStatus("Button clicked"); } }); add(b); } }
= bar on clicking the button with mouse.

180 Choose the correct output for the given code /*<applet code="MyControl10" width=300
height=300> </applet>*/ import java.applet.*; import java.awt.*; import java.awt.event.*;
public class MyControl10 extends Applet implements ItemListener { CheckboxGroup g; Checkbox
c1,c2,c3; int red,green,blue; public void init() { g=new CheckboxGroup(); c1=new
Checkbox("Red",g,false); c2=new Checkbox("Green",g,false); c3=new Checkbox("Blue",g,true);
setLayout(null); c1.setBounds(20,20,70,20); c2.setBounds(20,45,70,20);
c3.setBounds(20,70,70,20); add(c1); add(c2); add(c3); c1.addItemListener(this);
c2.addItemListener(this); c3.addItemListener(this); red=blue=green=0; } public void
itemStateChanged(ItemEvent ie) { red=green=blue=0; if(c1.getState()) red=255;
if(c2.getState()) green=255; if(c3.getState()) blue=255; repaint(); } public void paint(Graphics g)
{ Color c=new Color(red,green,blue); g.setColor(c); g.fillRect(90,20,100,100); } }
2 Y2 A 2 All of the above

No comments:

Post a Comment

java program (Tree)