0% found this document useful (0 votes)
19 views

mcq_java_3_eventhandling

Uploaded by

vinantymhatre02
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

mcq_java_3_eventhandling

Uploaded by

vinantymhatre02
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Q. 1.

The Following steps are required to perform Implement the Listener interface and overrides

its methods Register the component with the Listener

(a) Exception Handling

(b) String Handling

(c) Event Handling

(d) None of the above

Answer: c

Q. 2 In which places can put the event handling code

(a) Same class

(b) Other class

(c) Annonymous class

(d) All mentioned above

Answer: d

Q. 3 Which package provides many event classes and Listener interfaces for event handling?

(a) java.awt

(b) java.awt.Graphics

(c) java.awt.event

(d) None of the above

Answer: c

Q. 4 To use the ActionListener interface it must be implemented by a class there are several ways

to do that find in the following?

(a) Creating a new class

(b) using the class the graphical component

(c) an anonymous inner class

(d) All mentioned above

Answer: d
Q. 5 The ActionListener interface is not used for handling action events?

(a) True

(b) False

Answer: b

Q. 6 The ActionListener interface is used for handling action events, For example, it's used by a

(a) JButton

(b) JCheckbox

(c) All of these

(d) JMenuItem

Answer: c

Q. 7 Which class is used for this Processing Method processActionEvent( )?

(a) Button,List,MenuItem

(b) Button,Checkbox,Choice

(c) Scrollbar,Component,Button

(d) None of the above

Answer: a

Q. 8 In Graphics class Which method is used to set the graphics current color to the specified color?

(a) public abstract void setFont(Font font)

(b) public abstract void setColor(Color c)

(c) public abstract void drawString(String str, int x, int y)

(d) None of the above

Answer: b
Q. 9 Which of the following method is used to determine the type of adjustment event?

(a) getType( )

(b) getEventType( )

(c) getAdjustmentType( )

(d) getEventObjectType( )

Answer: c

Q. 10 TextField generates event.

(a) ActionEvent,ItemEvent

(b) ActionEvent, TextEvent

(c) ScrollEvent,TextEvent

(d) ActionEvent, ScrollEvent

Answer: b

Q. 11 void keyTyped(KeyEvent ke) called when a key on the keyboard is .

(a) pressed and then released.

(b) pressed

(c) released

(d) none of the above

Answer: a

Q. 12 Which event is generated when the position of scrollbar is changed?

(a) KeyEvent

(b) MouseEvent

(c) ItemEvent

(d) AdjustmentEvent

Answer: d
Q. 13 The signature for the registration method for a ActionEvent should be .

(a) public void addActionListener(ActionEvent L)

(b) public void setAction(ActionListener L)

(c) public void setActionListener(ActionListener L)

(d) public void addActionListener(ActionListener L)

Answer: d

Q. 14 Which of the following component generates ActionEvent?

(a) Window

(b) RadioButton

(c) ScrollBar

(d) None

Answer: d

Q. 15 method is used to register a keyboard event listener.

(a) KeyListener( )

(b) addKeyListener( )

(c) addKeyListenerEvent( )

(d) eventKeyboardListener( )

Answer: b

Q. 16 Name the method defined in EventObject class that returns the object generated from the event.

(a) getEvent( )

(b) getObject( )

(c) getId( )

(d) getSource( )

Answer: d
Q. 17 The MouseListener interface is used to make mouse handling.

(a) True

(b) False

Answer: a

Q. 18 ActionEvent is applied on

(a) Frame

(b) Checkbox, Choice, List

(c) Scrollbar

(d) Button, TextField, List, Menu

Answer: d

Q. 19 ComponentEvent is the super class of .

(a) FocusEvent

(b) MouseEvent

(c) WindowEvent

(d) All of the above

Answer: d

Q. 20 If we close an applet window events will be generated.

(a) ActionEvent

(b) ComponentEvent

(c) AdjustmentEvent

(d) WindowEvent

Answer: d
Q. 21 Which of the following component generate ActionEvent?

(a) ScrollBar

(b) Window

(c) RadioButton

(d) None of these

Answer: d

Q. 22 Which Listener handles all List related Events?

(a) ItemListener

(b) InputEvent

(c) SelectEvent

(d) ListEvent

Answer: a

Q. 23 How to obtain the command name for invoking ActionEvent?

(a) getCommandName( )

(b) getActionEventCommand( )

(c) getActionCmd( )

(d) getActionCommand( )

Answer: d

Q. 24 ComponentEvent is the superclass of

(a) ActionEvent

(b) ItemEvent

(c) TextEvent

(d) All of above

Answer: d
Q. 25 When we need to use Checkbox or Item from the list or use a checkable Menu an is generated.

(a) ActionEvent

(b) ItemEvent

(c) MenuEvent

(d) ClickEvent

Answer: b

Q. 26 Which of the following constant is not defined in WindowEvent class?

(a) WINDOW_ACTIVATED

(b) WINDOW_CLOSED

(c) WINDOW_DEICONIFIED

(d) None of these

Answer: d

Q. 27 Which of the following is not the method of handling window event?

(a) void windowClosed(WindowEvent we)

(b) void windowClosing(WindowEvent we)

(c) void windowAfterClosing(WindowEvent we)

(d) All of these

Answer: c

Q. 28 Which method is used to process mouse click?

(a) public void mouseClicked(MouseListener m)

(b) public void mouseIsClicked(MouseEvent m)

(c) public void mouseClicked(MouseEvent m)

(d) public void mouseClick(MouseEvent m)

Answer: c
Q. 29 Which class is used for this processing method processActionEvent( ) method?

(a) Button, List, MenuItem

(b) Button,Checkbox,Choice

(c) ScrollBar, Component, Button

(d) None of the above.

Answer: a

Q. 30 Which of this package contains all the classes and methods required for event handling in Java.

(a) java.applet

(b) java.awt

(c) java.event

(d) java.awt.event

Answer: d

Q. 31 Name the method defined in EvenObject class that returns the object generated from the event.

(a) getEvent( )

(b) getObject( )

(c) getId( )

(d) getSource( )

Answer: d

Q. 32 Which of these interfaces define a method actionPerformed()

(a) ComponentListener

(b) ContainerListener

(c) ActionListener

(d) InputListener

Answer: c
Q. 33 Button Control implements following listener interface.

(a) ItemListener

(b) ActionListener

(c) FlowListener

(d) Adapter

Answer: b

Q. 34 Clicking the closing button on the upper right corner of a frame generates a (n)‐event.

(a) ItemEvent

(b) WindowEvent

(c) MouseMotionEvent

(d) ComponentEvent

Answer: b

Q. 35 Which of the following method must be overridden in the order to handle KeyEvent.

(a) keyPressed(KeyEvent obj)

(b) KeyReleased(KeyEvent obj)

(c) KeyTyped(KeyEvent obj)

(d) All of these

Answer: d

Q. 36 Which of these methods can be used to know the degree of adjustment made by the user?

(a) getValue( )

(b) getAdjustmentType( )

(c) getAdjustmentValue( )

(d) getAdjustmentAmount( )

Answer: c
Q. 37 MouseEvent is subclass of which of the following class?

(a) ComponentEvent

(b) ContainerEvent

(c) ItemEvent

(d) InputEvent

Answer: d

Q. 38 The is an object that is notified when an event occurs.

(a) Listener

(b) Sources

(c) Event

(d) None of the above

Answer: a

Q. 39 What is the use of String getActionCommand( ) method of ActionEvent class?

(a) to obtain the label (caption) of Button

(b) to obtain the reference of Button

(c) to obtain object of Button

(d) to obtain the label (caption) and object of Button

Answer: a
Q. 40. Select the missing statement in given

code import java.awt.*;

import java.applet.*;

/*

<applet code="mouse" width=300 height=100>

</applet>

*/

public class mouse extends Applet implements MouseListener, MouseMotionListener

String msg = "";

intmouseX = 0,

mouseY = 0public

void init()

public void mouseClicked(MouseEvent me)

mouseX = 0;

mouseY =

10; msg =

"Mouse

clicked.";re

paint();

public void mouseEntered(MouseEvent me)

mouseX = 0;

mouseY

= 10;

msg =
"Mouse

entered.";repaint();

public void mouseExited(MouseEvent me)

mouseX = 0;

mouseY =

10; msg =

"Mouse

exited.";rep

aint();

public void mousePressed(MouseEvent me)

mouseX =

me.getX();mo

useY

me.getY();m

sg = "Down";

repaint();

public void mouseReleased(MouseEvent me)

mouseX =

me.getX();mo

useY

me.getY();m

sg = "Up";
repaint();

public void mouseDragged(MouseEvent me)

mouseX =

me.getX();m

ouseY

me.getY();ms

g = "*";

showStatus("Dragging mouse at " + mouseX + ", " + mouseY);

repaint();

public void mouseMoved(MouseEvent me)

showStatus("Moving mouse at " + me.getX() + ", " + me.getY());

public void paint(Graphics g)

g.drawString(msg, mouseX, mouseY);

a) addMouseMotionListener(this);

b) addMouseListener(this);

c) import java.awt.event.*;

d) all of above

Answer: d
Q. 41. Select the proper output for following

code Import java.awt.*;

import java.applet.*;

public class list2 extends Applet

public void init()

List l= new

List(2,true);

l.add("java"

);

l.add("c++");

l.add("kkk"); add(l);

/*<applet code=list2.class height=200 width=200>

</applet>*/

Answer: c

Q. 42. To get the following output complete the code given below.

import java.awt.*;

import javax.swing.*;

<applet code="jscroll" width=300 height=250>

</applet>

*/

public class jscroll extends JApplet

public void init(){

Container contentPane = getContentPane();


contentPane.setLayout(new BorderLayout());

i t v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;

i t h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;

JScrollPanejsp = new JScrollPane(jp, v, h);

contentPane.add(jsp, BorderLayout.CENTER);

a) Container contentPane = getContentPane(); contentPane.setLayout(new GridLayout());

b) JPaneljp = new JPanel(); jp.setLayout(new GridLayout(20, 20));

c) int b = 0;

for(int i = 0; i < 20; i++) { for(int j = 0; j < 20; j++) {

jp.add(new JButton("Button " + b));

++b;

d) JPaneljp = new JPanel(); jp.setLayout(new GridLayout(3,3)); int b = 0;

for(int i = 0; i <3; i++)

for(int j = 0; j <3; j++)

jp.add(new JButton("Button " + b));

++b

Answer: d
Q. 43. Select proper code for given output

A.

importjava.awt.*; importjava.applet.*;

public class choice11 extends Applet

public void init(){

Choice os=new Choice();os.add("wnn18");

os.add("wnnxp");

os.add("wnnnt");

os.add("win

2000");add(os);

/ <applet code="choice11" height=200 width=300>

</applet>*/

B.

importjava.awt.*; importjava.applet.*;

public class choice11 extends Applet

public void init()

Choice os=new Choice();

os.add("wnn18");

os.add("wnnxp");

add(os);

/*<applet code="choice11" height=200 width=300>

</applet>*/
C.

importjava.awt.*; importjava.applet.*;

public class choice11 extends Applet

public void init()

Choice os=new Choice();

os.add("wnn18");

os.add("wnnxp");

os.add("wnnnt");

os.add("win 2000");

add(os);

D.

importjava.awt.*; importjava.applet.*;

public class choice11 extends Applet

public void init()

Choice os=new Choice();

os.add("wnn18");

os.add("wnnxp");

os.add("wnnnt");

os.add("win 2000");

/*<applet code="choice11" height=200 width=300>

</applet>*/

Answer: a
Q. 44. Select the missing statement in the program to get the following output

importjava.awt.*;

importjava.awt.event.*;

importjavax.swing.*;

<applet code="combodemo" width=300 height=100>

</applet>

*/

public class combodemo extends JApplet implements itemListener

JLabel jl;

Image Iconfrance, germany, italy, japan;

public void init(){

Container contentPane = getContentPane();

contentPane.setLayout(new FlowLayout());

JComboBoxjc = new JComboBox();

jc.addItem("France"); jc.addItem("Germany");

jc.addItem("Italy"); jc.addItem("Japan");

jc.addItemListener(this); contentPane.add(jc);

contentPane.add(jl);

public void itemStateChanged(ItemEventie)

String s = (String)ie.getItem();

jl.setIcon(new ImageIcon(s + ".gif"));

}
a) jl = new JLabel(new ImageIcon("star.gif"));

b) jl = new JLabel("star.gif");

c) jl = new JLabel( ImageIcon("star.gif"));

d) JLabel(new ImageIcon("star.gif"));

Answer: a
Q. 45. Select the missing statement in the program for following output

import java.awt.*;

public class MenuDemo extends Frame

public static void main(String args[])

MenuDemo m = new

MenuDemo();m.setVisible(true);

MenuBar mbr = new

MenuBar();

m.setMenuBar(mbr);

Menu filemenu = new Menu("File"); Menu

editmenu = new Menu("Edit"); Menu

viewmenu = new Menu("View");

mbr.add(filemenu); mbr.add(editmenu);

MenuItem new1 = new MenuItem("New");

MenuItem open1 = new MenuItem("Open");

filemenu.add(new1);

filemenu.add(open1);

A. mbr.add(view);

B. mbr.add(menu);

C. mbr.add(vieweditmenu);

D. mbr.add(viewmenu);

Answer: d
Q.46. Consider the following output. Find the missing statement in the program.

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

import javax.swing.*;

/*

<applet code="SimpleKey1" width=300 height=100>

</applet>

*/

public class SimpleKey1 extends JApplet

implements KeyListener

String msg = "";

int X = 10, Y = 20; public void init()

addKeyListener(this);

requestFocus();

public void keyPressed(KeyEvent ke)

showStatus("Key Down");

public void keyReleased(KeyEvent ke)

showStatus("Key Up");

public void keyTyped(KeyEvent ke)

msg +=

ke.getKeyChar();

repaint();
}

public void paint(Graphics g)

g.drawString(msg, X, Y);

a) Missing Semicolon

b) }

c) {

d) ()

Answer: b
Q.47.For 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>*/
a) actionPerformed(ActionEvent ae)

b) itemStateChanged(ActionEvent ie)

c) itemStateChanged(ItemEvent ie)

d) adjustmentPerformed(AdjustmentEvent ae)

Answer: c

You might also like